//
//  Reports.m
//  A One POS
//
//  Created by AonePOS on 24/09/13.
//  Copyright (c) 2013 AonePOS. All rights reserved.
//

#import "Reports.h"
#import <QuartzCore/QuartzCore.h>
#import "ePOS-Print.h"
#import "ShowMess.h"
#import <StarIO/SMPort.h>
#import "PrinterFunctions.h"
#import "CommonEnum.h"

#import "DataBaseManager.h"
#import "Settings.h"
#import "Home.h"
#import "Profile.h"
#import "Inventory.h"
#import "Customers.h"
#import "Employees.h"
#import "Stores.h"
#import "Contacts.h"
#import "ServersyncClass.h"

#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v)  ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)
@interface Reports ()

@end

@implementation Reports
{
    ServersyncClass *serverSyncClassObject;
     general_data *generalDataObject;
}

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    generalDataObject =[general_data new];
    [generalDataObject  GetuserDataVariablesMethod];
    serverSyncClassObject=[ServersyncClass new];
    [NSThread detachNewThreadSelector:@selector(ServerSyncronizationMethod) toTarget:serverSyncClassObject withObject:nil];
    
     //appDelegate =  (AppDelegate *)[UIApplication sharedApplication].delegate;
    [super viewDidLoad];
    
   // [NSThread detachNewThreadSelector:@selector(ServerSyncronizationMethod) toTarget:[ServersyncClass sharedInstance] withObject:nil];
    
    y=0;
    if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7.0"))
    {
        y=y+20;
        
        
    }
    CGFloat width,height;
    width=self.view.frame.size.width;
    height=self.view.frame.size.height;
    //// //NSLog(@" %f,%f",width,height);
    
    backgroundcolorview=[[UIView alloc]init];
    backgroundcolorview.frame=CGRectMake(0,y,width,height-100);
    [backgroundcolorview  setBackgroundColor:[UIColor colorWithPatternImage:[[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"background" ofType:@"jpg"]]]];
    
    [self.view addSubview:backgroundcolorview];
    
    // [ContactsBtn setImage:[[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"contactsactive" ofType:@"png"]] forState:UIControlStateNormal];
    
    sidemenu=[[UIView alloc]init];
    sidemenu.frame=CGRectMake(0, 1,170 ,height-150);
    //sidemenu.hidden=YES;
    //[sidemenu  setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"bluecolorstrip.jpg"]]];
    [sidemenu  setBackgroundColor:[UIColor colorWithPatternImage:[[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"bluecolorstrip" ofType:@"jpg"]]]];
    
    
    NSString *pagetitle;
    pagetitle=@"Reports";
    
    
    
    navBar = [[UINavigationBar alloc] init];
    navBar.frame=CGRectMake(0, 0,width , 50.0);
    
    [navBar setBackgroundImage:[UIImage imageNamed:@"logo-login-bg-short.png"] forBarMetrics:UIBarMetricsDefault];
    
    //[navBar setBackgroundColor:[UIColor blackColor]];
    UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 100, 50)];
    titleLabel.font=[UIFont boldSystemFontOfSize:30.0];
    titleLabel.textColor = [UIColor blackColor];
    titleLabel.backgroundColor = [UIColor clearColor];
    titleLabel.text =pagetitle;
    [self.navigationItem setTitleView:titleLabel];
    
    
    //navItem.title = pagetitle;
    [navBar pushNavigationItem:self.navigationItem animated:false];
    
    [backgroundcolorview addSubview:navBar];
    
    
    menubutton = [UIButton buttonWithType:UIButtonTypeCustom];
    [menubutton setFrame:CGRectMake(0,0,50,50)];
    [menubutton addTarget:self action:@selector(menuclicked) forControlEvents:UIControlEventTouchUpInside];
    
    [menubutton setImage:[[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"arrow" ofType:@"png"]] forState:UIControlStateNormal];
    [navBar addSubview:menubutton];
    
    
    logoBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [logoBtn setFrame:CGRectMake(60,0,250,50)];
    // [logoBtn addTarget:self action:@selector(menuclicked) forControlEvents:UIControlEventTouchUpInside];
    
    //[logoBtn setImage:[UIImage imageNamed:@"headeraonelogo.png"] forState:UIControlStateNormal];
    [logoBtn setImage:[[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"headeraonelogo" ofType:@"png"]] forState:UIControlStateNormal];
    
    [navBar addSubview:logoBtn];
    sationLbl=[[UILabel alloc] init];
    
    sationLbl.frame=CGRectMake(navBar.frame.size.width-280, 5,100, 40);
    
    [sationLbl setFont:[UIFont systemFontOfSize:13.0f]];
    [sationLbl setBackgroundColor:[UIColor clearColor]];
    [sationLbl setTextColor:[UIColor blackColor]];
    [sationLbl setText:@"Station No:1"];
    sationLbl.lineBreakMode = NSLineBreakByWordWrapping;
    sationLbl.numberOfLines = 2;
    [sationLbl setTextAlignment:NSTextAlignmentLeft];
    [navBar addSubview:sationLbl];
    
    
    EmpIdlbl=[[UILabel alloc] init];
    EmpIdlbl.frame=CGRectMake(navBar.frame.size.width-193, 5,150, 40);
    
    [EmpIdlbl setFont:[UIFont systemFontOfSize:13.0f]];
    [EmpIdlbl setBackgroundColor:[UIColor clearColor]];
    [EmpIdlbl setTextColor:[UIColor blackColor]];
    [EmpIdlbl setText:[NSString stringWithFormat:@"Employee Id: %@",[generalDataObject  userID]]];
    EmpIdlbl.lineBreakMode = NSLineBreakByWordWrapping;
    // EmpIdlbl.numberOfLines = 2;
    [EmpIdlbl setTextAlignment:NSTextAlignmentLeft];
    [navBar addSubview:EmpIdlbl];
    
    
    Timelbl=[[UILabel alloc] init];
    Timelbl.frame=CGRectMake(navBar.frame.size.width-62, 6,80, 40);
    [Timelbl setFont:[UIFont systemFontOfSize:13.0f]];
    [Timelbl setBackgroundColor:[UIColor clearColor]];
    [Timelbl setTextColor:[UIColor blackColor]];
    NSDate *aDate = [NSDate date];
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateStyle:NSDateFormatterShortStyle];
    [formatter setTimeStyle:NSDateFormatterNoStyle];
    [formatter setDateFormat:@"HH:mm:ss"];
    NSString *datestr;
    datestr=[formatter stringFromDate:aDate];
    Timelbl.text=datestr;
    //Timelbl.text=[NSString stringWithFormat:@"%@:%@",@"Time",datestr];
    
    // timer is set & will be triggered each second
    //[NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(showTime) userInfo:nil repeats:YES];
    Timelbl.lineBreakMode = NSLineBreakByWordWrapping;
    Timelbl.numberOfLines = 2;
    [Timelbl setTextAlignment:NSTextAlignmentLeft];
    [navBar addSubview:Timelbl];
    p=1;
    @autoreleasepool {
        for (int i=0; i< 10; i++)
        {
            categorybutton = [UIButton buttonWithType:UIButtonTypeCustom];
            
            [categorybutton setFrame:CGRectMake(0,p,170,40)];
            [categorybutton addTarget:self action:@selector(categotybuttonclicked:) forControlEvents:UIControlEventTouchUpInside];
            categorybutton.tag=i;
            if (categorybutton.tag == 0)
            {
                [categorybutton setImage:[UIImage imageNamed:@"posnormal2.png"] forState:UIControlStateNormal];
            }
            
            else if (categorybutton.tag == 1)
            {
                [categorybutton setImage:[UIImage imageNamed:@"profilenormal2.png"] forState:UIControlStateNormal];
            }
            else if (categorybutton.tag == 2)
            {
                [categorybutton setImage:[UIImage imageNamed:@"inventorynormal2.png"] forState:UIControlStateNormal];
            }
            else if(categorybutton.tag == 3)
            {
                [categorybutton setImage:[UIImage imageNamed:@"customernormal2.png"] forState:UIControlStateNormal];
            }
            else if (categorybutton.tag == 4)
            {
                [categorybutton setImage:[UIImage imageNamed:@"employeenormal2.png"] forState:UIControlStateNormal];
            }
            else if(categorybutton.tag == 5)
            {
                [categorybutton setImage:[UIImage imageNamed:@"settingsnormal2.png"] forState:UIControlStateNormal];
            }
            else if(categorybutton.tag == 6)
            {
                [categorybutton setImage:[UIImage imageNamed:@"reportsactive2.png"] forState:UIControlStateNormal];
            }
            else if(categorybutton.tag == 7)
            {
                [categorybutton setImage:[UIImage imageNamed:@"contactsnormal2.png"] forState:UIControlStateNormal];
            }
            else if (categorybutton.tag == 8)
            {
                [categorybutton setImage:[UIImage imageNamed:@"storesnormal.png"] forState:UIControlStateNormal];
            }
            
            else if (categorybutton.tag == 9)
            {
                //[categorybutton setImage:[UIImage imageNamed:@"bluecolorstrip.jpg"] forState:UIControlStateNormal];
            }
            [sidemenu addSubview:categorybutton];
            p=p+categorybutton.frame.size.height;
        }
    }
  
    
    mainview=[[UIView alloc]init];
    mainview.frame=CGRectMake(20,60,width-40,height-200);
    [mainview setBackgroundColor:[UIColor grayColor]];
    [mainview  setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"hqbackground69opacity.png"]]];
    [backgroundcolorview addSubview:mainview];
    maintoolBar = [[UIToolbar alloc] init];
    maintoolBar.frame = CGRectMake(0, 0, mainview.frame.size.width, 40);
    [maintoolBar setBackgroundImage:[UIImage imageNamed:@"toprightmenu.png"] forToolbarPosition:UIToolbarPositionAny barMetrics:UIBarMetricsDefault];
    
    NSMutableArray *items=[[NSMutableArray alloc]init];
    backButton = [UIButton buttonWithType:UIButtonTypeCustom];
    backButton.frame = CGRectMake(0, 0, 150, 60);
    
    [backButton addTarget:self action:@selector(backButtonTapped1) forControlEvents:UIControlEventTouchUpInside];
    // [backButton setBackgroundImage:[UIImage imageNamed:@"topright-highlightitem-textbg.png"] forState:UIControlStateNormal];
    backButton.tag=[items indexOfObject:backButton];
    UIImage *btnImg = [UIImage imageNamed:@"highlightedtopmenuitem.png"];
    UIImage *btnGreyImg = [btnImg stretchableImageWithLeftCapWidth:0 topCapHeight:1];
    [backButton setBackgroundImage:btnGreyImg forState:UIControlStateNormal];
    [backButton setTitle:@"Application" forState:UIControlStateNormal];
    [backButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    backButton.showsTouchWhenHighlighted = YES;
    
    UIBarButtonItem *backBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:backButton];
    
    [items  addObject:backBarButtonItem];
    [items addObject:[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil]];
    backButton2 = [UIButton buttonWithType:UIButtonTypeCustom];
    backButton2.frame = CGRectMake(0, 0, 150, 60);
    [backButton2 setTitle:@"Application2" forState:UIControlStateNormal];
    [backButton2 addTarget:self action:@selector(backButtonTapped2) forControlEvents:UIControlEventTouchUpInside];
    backButton2.tag=[items indexOfObject:backButton2];
    //[backButton2 setBackgroundImage:[UIImage imageNamed:@"topright-highlightitem-textbg.png"] forState:UIControlStateNormal];
    backButton2.showsTouchWhenHighlighted = YES;
    
    
    UIBarButtonItem *backBarButtonItem2 = [[UIBarButtonItem alloc] initWithCustomView:backButton2];
    
    [items  addObject:backBarButtonItem2];
    [items addObject:[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil]];
    backButton3 = [UIButton buttonWithType:UIButtonTypeCustom];
    backButton3.frame = CGRectMake(0, 0, 150,60);
    [backButton3 setTitle:@"Application3" forState:UIControlStateNormal];
    
    [backButton3 addTarget:self action:@selector(backButtonTapped3) forControlEvents:UIControlEventTouchUpInside];
    //[backButton3 setBackgroundImage:[UIImage imageNamed:@"topright-highlightitem-textbg.png"] forState:UIControlStateNormal];
    backButton3.showsTouchWhenHighlighted = YES;
    backButton3.tag=[items indexOfObject:backButton3];
    //UIImage *backButtonImage = [UIImage imageNamed:@"back-button.png"];
    //[backButton setImage:backButtonImage forState:UIControlStateNormal];
    
    // backButton.imageEdgeInsets = UIEdgeInsetsMake(10, 10, 10, 10);
    
    UIBarButtonItem *backBarButtonItem3 = [[UIBarButtonItem alloc] initWithCustomView:backButton3];
    
    [items  addObject:backBarButtonItem3];
    
    [maintoolBar setItems:items animated:NO];
    //[mainview addSubview:maintoolBar];
    
    
    
    
    logoimageview=[[UIImageView alloc]init];
    logoimageview.frame=CGRectMake(50, (backgroundcolorview.frame.size.height)+5+y,(height-(backgroundcolorview.frame.size.height)-30), (height-(backgroundcolorview.frame.size.height)-30));
    [logoimageview setImage:[[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"aoneposlogo" ofType:@"png"]]];
    [self.view addSubview:logoimageview];
    
    helpiconButton = [UIButton buttonWithType:UIButtonTypeCustom];
    
    [helpiconButton setFrame:CGRectMake(width-180,y+40,70,70)];
    [helpiconButton addTarget:self action:@selector(helpiconclicked) forControlEvents:UIControlEventTouchUpInside];
    
    //[helpiconButton setImage:[UIImage imageNamed:@"helpicon.png"] forState:UIControlStateNormal];
    [helpiconButton setImage:[[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"helpicon" ofType:@"png"]] forState:UIControlStateNormal];
    
    [self.view addSubview:helpiconButton];
    logouticonButton = [UIButton buttonWithType:UIButtonTypeCustom];
    
    [logouticonButton setFrame:CGRectMake(width-100,y+40,70,70)];
    [logouticonButton addTarget:self action:@selector(logoutButtonClicked) forControlEvents:UIControlEventTouchUpInside];
    
    //[logouticonButton setImage:[UIImage imageNamed:@"logoutbutton.png"] forState:UIControlStateNormal];
    [logouticonButton setImage:[[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"logoutbutton" ofType:@"png"]] forState:UIControlStateNormal];
    [self.view addSubview:logouticonButton];
    isLandScope = UIInterfaceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation);
    [self updateUI];
    [super viewWillAppear:YES];
    
    
    //Divya Coding
    
    whiteView=[[UIView alloc]init];
    whiteView.frame=CGRectMake(10,10,mainview.frame .size.width-20,mainview.frame.size.height-20);
    [whiteView  setBackgroundColor:[UIColor whiteColor]];
    [mainview addSubview:whiteView];
    
    blueView = [[UIView alloc]init];
    blueView.frame=CGRectMake(10, 10, whiteView.frame.size.width-20, whiteView.frame.size.height-20);
    [blueView setBackgroundColor:[UIColor colorWithRed:0.0f green:74.0f/255.0f blue:132.0f/255.0f alpha:1.0f]];
    [whiteView addSubview:blueView];
    
    CGFloat RWdth=blueView.frame.size.width/4;
    CGFloat Fwdth=RWdth/2;
    fromLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, 5, Fwdth,30)];
    fromLabel.text = @"From";
    
    fromLabel.font=[UIFont systemFontOfSize:22.0f];
    fromLabel.backgroundColor = [UIColor clearColor];
    fromLabel.textColor= [UIColor whiteColor];
    [blueView addSubview:fromLabel];
    
    fromTFUp = [[UITextField alloc]initWithFrame:CGRectMake( fromLabel.frame.size.width,5, Fwdth+30,30)];
    fromTFUp.delegate=self;
    fromTFUp.borderStyle= UITextBorderStyleRoundedRect;
    fromTFUp.textColor =[UIColor blackColor];
    fromTFUp.delegate=self;
    [blueView addSubview:fromTFUp];
    
    fromTFDown = [[UITextField alloc]initWithFrame:CGRectMake(fromLabel.frame.size.width+fromTFUp.frame.size.width+5,5, Fwdth+30,30)];
    fromTFDown.delegate=self;
    fromTFDown.borderStyle= UITextBorderStyleRoundedRect;
    fromTFDown.textColor =[UIColor blackColor];
    fromTFDown.delegate=self;
    [blueView addSubview:fromTFDown];
    
    toLabel = [[UILabel alloc]init];
    
    toLabel.frame=CGRectMake(fromLabel.frame.size.width+30+fromTFUp.frame.size.width+140,5, RWdth-50,30);
    
    toLabel.text=@"To";
    toLabel.font=[UIFont systemFontOfSize:22.0f];
    toLabel.backgroundColor = [UIColor clearColor];
    toLabel.textColor= [UIColor whiteColor];
    [blueView addSubview:toLabel];
    
    
    toTFUp = [[UITextField alloc]initWithFrame:CGRectMake(fromLabel.frame.size.width+fromTFUp.frame.size.width+toLabel.frame.size.width+100,5, Fwdth+30,30)];
    toTFUp.borderStyle= UITextBorderStyleRoundedRect;
    toTFUp.delegate=self;
    toTFUp.textColor =[UIColor blackColor];
    [blueView addSubview:toTFUp];
    
    toTFDown = [[UITextField alloc]initWithFrame:CGRectMake(fromLabel.frame.size.width+fromTFUp.frame.size.width+toLabel.frame.size.width+100+toTFUp.frame.size.width+5,5, Fwdth+30,30)];
    toTFDown.borderStyle= UITextBorderStyleRoundedRect;
    toTFDown.delegate=self;
    toTFDown.textColor =[UIColor blackColor];
    [blueView addSubview:toTFDown];
    
    departLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, 45, RWdth-20,30)];
    departLabel.text=@"Department";
    departLabel.font=[UIFont systemFontOfSize:22.0f];
    departLabel.backgroundColor = [UIColor clearColor];
    departLabel.textColor= [UIColor whiteColor];
    [blueView addSubview:departLabel];
    
    departmentButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    departmentButton.frame=CGRectMake(departLabel.frame.size.width,45, RWdth+20,30);
    [departmentButton setBackgroundImage:[UIImage imageNamed:@"drop-down-icon.png"] forState:UIControlStateNormal];
    [departmentButton setTitle:@"All" forState:UIControlStateNormal];
    departmentButton.titleLabel.font = [UIFont systemFontOfSize:20.0f];
    [departmentButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [departmentButton addTarget:self action:@selector(departmentClick) forControlEvents:UIControlEventTouchUpInside];
    [blueView addSubview:departmentButton];
    
    paymentLabel = [[UILabel alloc]initWithFrame:CGRectMake(departLabel.frame.size.width+departmentButton.frame.size.width+10,45, RWdth-20,30)];
    paymentLabel.text=@"Payment";
    paymentLabel.font=[UIFont systemFontOfSize:22.0f];
    paymentLabel.backgroundColor = [UIColor clearColor];
    paymentLabel.textColor= [UIColor whiteColor];
    [blueView addSubview:paymentLabel];
    
    
    paymentButton =  [UIButton buttonWithType:UIButtonTypeRoundedRect];
    paymentButton.frame=CGRectMake(departLabel.frame.size.width+departmentButton.frame.size.width+paymentLabel.frame.size.width-20,45, RWdth+20,30);
    [paymentButton setBackgroundImage:[UIImage imageNamed:@"drop-down-icon.png"] forState:UIControlStateNormal];
    [paymentButton setTitle:@"All" forState:UIControlStateNormal];
    paymentButton.titleLabel.font = [UIFont systemFontOfSize:20.0f];
    [paymentButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [paymentButton addTarget:self action:@selector(paymentClick) forControlEvents:UIControlEventTouchUpInside];
    [blueView addSubview:paymentButton];
    
    Reporttypelbl = [[UILabel alloc]initWithFrame:CGRectMake(10, 85, RWdth-20,30)];
    Reporttypelbl.text=@"Report";
    Reporttypelbl.font=[UIFont systemFontOfSize:22.0f ];
    Reporttypelbl.backgroundColor = [UIColor clearColor];
    Reporttypelbl.textColor= [UIColor whiteColor];
    [blueView addSubview:Reporttypelbl];
    
    ReporttypeBtn =  [UIButton buttonWithType:UIButtonTypeRoundedRect];
    ReporttypeBtn.frame=CGRectMake(departLabel.frame.size.width,85, RWdth+20,30);
    [ReporttypeBtn setBackgroundImage:[UIImage imageNamed:@"drop-down-icon.png"] forState:UIControlStateNormal];
    ReporttypeBtn.titleLabel.font = [UIFont systemFontOfSize:12.0f];
    //[ReporttypeBtn setTitle:@"Invoice Total Report" forState:UIControlStateNormal];
    [ReporttypeBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [ReporttypeBtn addTarget:self action:@selector(ReportTypeBtnClick) forControlEvents:UIControlEventTouchUpInside];
    [blueView addSubview:ReporttypeBtn];
    
    
    Searchlbl = [[UILabel alloc]initWithFrame:CGRectMake(departLabel.frame.size.width+departmentButton.frame.size.width+10,85, RWdth-20,30)];
    Searchlbl.text=@"Search";
    Searchlbl.font=[UIFont systemFontOfSize:22.0f];
    Searchlbl.backgroundColor = [UIColor clearColor];
    Searchlbl.textColor= [UIColor whiteColor];
    [blueView addSubview:Searchlbl];
    
    searchField = [[UITextField alloc]initWithFrame:CGRectMake(departLabel.frame.size.width+departmentButton.frame.size.width+paymentLabel.frame.size.width-20,85, RWdth+20,30)];
    searchField.delegate=self;
    [searchField setAutocorrectionType:UITextAutocorrectionTypeNo];
    searchField.borderStyle = UITextBorderStyleRoundedRect;
    searchField.textColor= [UIColor blackColor];
    [blueView addSubview:searchField];
    
    
    //Updates in reports of divya coding
    
    
    empIdlabel = [[UILabel alloc]initWithFrame:CGRectMake(10, 125, RWdth-20,30)];
    empIdlabel.text=@"Emp ID";
    empIdlabel.font=[UIFont systemFontOfSize:22.0f];
    empIdlabel.backgroundColor = [UIColor clearColor];
    empIdlabel.textColor= [UIColor whiteColor];
    [blueView addSubview:empIdlabel];
    
    empIdBtn =  [UIButton buttonWithType:UIButtonTypeRoundedRect];
    empIdBtn.frame=CGRectMake(departLabel.frame.size.width,125, RWdth+20,30);
    [empIdBtn setBackgroundImage:[UIImage imageNamed:@"drop-down-icon.png"] forState:UIControlStateNormal];
    [empIdBtn setTitle:@"All" forState:UIControlStateNormal];
    empIdBtn.titleLabel.font = [UIFont systemFontOfSize:20.0f];
    [empIdBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [empIdBtn addTarget:self action:@selector(empIdBtnClick) forControlEvents:UIControlEventTouchUpInside];
    [blueView addSubview:empIdBtn];
    
    orderStatusLbl = [[UILabel alloc]initWithFrame:CGRectMake(10, 165, RWdth-20,30)];
    orderStatusLbl.text=@"Order Status";
    orderStatusLbl.font=[UIFont systemFontOfSize:22.0f];
    orderStatusLbl.backgroundColor = [UIColor clearColor];
    orderStatusLbl.textColor= [UIColor whiteColor];
    [blueView addSubview:orderStatusLbl];
    
    
    orderStatusBtn =  [UIButton buttonWithType:UIButtonTypeRoundedRect];
    orderStatusBtn.frame=CGRectMake(departLabel.frame.size.width,165, RWdth+20,30);
    [orderStatusBtn setBackgroundImage:[UIImage imageNamed:@"drop-down-icon.png"] forState:UIControlStateNormal];
    orderStatusBtn.titleLabel.font = [UIFont systemFontOfSize:20.0f];
    [orderStatusBtn setTitle:@"complete" forState:UIControlStateNormal];
    [orderStatusBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [orderStatusBtn addTarget:self action:@selector(orderStatusBtnClick) forControlEvents:UIControlEventTouchUpInside];
    [blueView addSubview:orderStatusBtn];
    
    
    
    customerIdLabel = [[UILabel alloc]initWithFrame:CGRectMake(departLabel.frame.size.width+departmentButton.frame.size.width+10,125, RWdth-20,30)];
    customerIdLabel.text=@"Store ID";
    customerIdLabel.font=[UIFont systemFontOfSize:22.0f];
    customerIdLabel.backgroundColor = [UIColor clearColor];
    customerIdLabel.textColor= [UIColor whiteColor];
    [blueView addSubview:customerIdLabel];
    
    
    customerIdBtn =  [UIButton buttonWithType:UIButtonTypeRoundedRect];
    customerIdBtn.frame= CGRectMake(departLabel.frame.size.width+departmentButton.frame.size.width+paymentLabel.frame.size.width-20,125, RWdth+20,30);
    [customerIdBtn setBackgroundImage:[UIImage imageNamed:@"drop-down-icon.png"] forState:UIControlStateNormal];
    [customerIdBtn setTitle:@"All" forState:UIControlStateNormal];
    customerIdBtn.titleLabel.font = [UIFont systemFontOfSize:20.0f];
    [customerIdBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [customerIdBtn addTarget:self action:@selector(customerBtnClick) forControlEvents:UIControlEventTouchUpInside];
    [blueView addSubview:customerIdBtn];
    
    
    //Updates in reports of divya coding
    
    SearchlistTable = [[UITableView alloc] initWithFrame:CGRectMake(departLabel.frame.size.width+departmentButton.frame.size.width+paymentLabel.frame.size.width-20,5, RWdth+20,80) style:UITableViewStylePlain];
    SearchlistTable.backgroundColor=[UIColor whiteColor];
    SearchlistTable.delegate = self;
    SearchlistTable.dataSource = self;
    SearchlistTable.scrollEnabled = YES;
    SearchlistTable.hidden=YES;
    [SearchlistTable.layer setBorderWidth: 1.0];
    [SearchlistTable.layer setBorderColor:[[UIColor grayColor] CGColor]];
    [blueView addSubview:SearchlistTable];
    
    goButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [goButton setTitle:@"Go" forState:UIControlStateNormal];
    goButton.frame=CGRectMake(departLabel.frame.size.width+Fwdth,240, 80,30);
    [goButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [goButton addTarget:self action:@selector(goButtonClick) forControlEvents:UIControlEventTouchUpInside];
    [goButton setBackgroundImage:[UIImage imageNamed:@"okay-button.png"] forState:UIControlStateNormal];
    [blueView addSubview:goButton];
    
    saveButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [saveButton setTitle:@"Save" forState:UIControlStateNormal];
    saveButton.frame=CGRectMake(departLabel.frame.size.width+RWdth,240, 80,30);
    [saveButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [saveButton addTarget:self action:@selector(saveButtonClick) forControlEvents:UIControlEventTouchUpInside];
    [saveButton setBackgroundImage:[UIImage imageNamed:@"okay-button.png"] forState:UIControlStateNormal];
    [blueView addSubview:saveButton];
    
    
    printerButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [printerButton setTitle:@"Print" forState:UIControlStateNormal];
    printerButton.frame=CGRectMake(departLabel.frame.size.width+RWdth+Fwdth,240, 80,30);
    [printerButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [printerButton addTarget:self action:@selector(printButtonClick:) forControlEvents:UIControlEventTouchUpInside];
    [printerButton setBackgroundImage:[UIImage imageNamed:@"okay-button.png"] forState:UIControlStateNormal];
    [blueView addSubview:printerButton];
    
    
    
    
    
    displayTableView = [[UITableView alloc]init];
    displayTableView.frame = CGRectMake(5,290,blueView.frame.size.width-10,blueView.frame.size.height-295);
    displayTableView.backgroundColor =[UIColor colorWithRed:0.0f green:74.0f/255.0f blue:132.0f/255.0f alpha:1.0f];
    displayTableView.delegate=self;
    displayTableView.dataSource= self;
    displayTableView.hidden=YES;
    [blueView addSubview:displayTableView];
    
    //Divya Coding
    
    invoiceTableView = [[UITableView alloc]init];
    invoiceTableView.frame = CGRectMake(5,290,blueView.frame.size.width-10,blueView.frame.size.height-295);
    invoiceTableView.backgroundColor =[UIColor colorWithRed:0.0f green:74.0f/255.0f blue:132.0f/255.0f alpha:1.0f];
    invoiceTableView.delegate=self;
    invoiceTableView.dataSource= self;
    invoiceTableView.hidden=YES;
    [blueView addSubview:invoiceTableView];
    
    
    departmentWiseTableView = [[UITableView alloc]init];
    departmentWiseTableView.frame = CGRectMake(5,290,blueView.frame.size.width-10,blueView.frame.size.height-295);
    departmentWiseTableView.backgroundColor =[UIColor colorWithRed:0.0f green:74.0f/255.0f blue:132.0f/255.0f alpha:1.0f];
    departmentWiseTableView.delegate=self;
    departmentWiseTableView.dataSource= self;
    departmentWiseTableView.hidden=YES;
  //  [blueView addSubview:departmentWiseTableView];
    
     helpiconButton.hidden=YES;
    //Divya department tableView
    // Do any additional setup after loading the view from its nib.
}
-(void)viewWillAppear:(BOOL)animated
{
    isLandScope = UIInterfaceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation);
    [self updateUI];
    if (!pastDataArray)
    pastDataArray=[[NSMutableArray alloc]init];
    SearchDataArray=[[NSMutableArray alloc]init];
    
    NSString *querySQL = [NSString stringWithFormat: @"SELECT item_id,item_name FROM invoice_items_table"];
    NSMutableArray *invoiceArray=[[NSMutableArray alloc]init];
    [[DataBaseManager dataBaseManager]execute:querySQL resultsArray:invoiceArray];
    
    @autoreleasepool {
        for (NSDictionary *myDict in invoiceArray)
        {
            [pastDataArray addObject:[myDict objectForKey:@"item_id"]];
            
            [pastDataArray addObject:[myDict objectForKey:@"item_name"]];

        }
    }
    
   
    
    
}
-(void)showTime
{
    
    NSDate *aDate = [NSDate date];
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateStyle:NSDateFormatterShortStyle];
    [formatter setTimeStyle:NSDateFormatterNoStyle];
    [formatter setDateFormat:@"HH:mm:ss"];
    NSString *datestr;
    datestr=[formatter stringFromDate:aDate];
    Timelbl.text=datestr;
    // Timelbl.text=[NSString stringWithFormat:@"%@:%@",@"Time",datestr];
    //Timelbl.text=[[NSDate date] description];

}

-(void)saveButtonClick
{
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSString *ReportsPath = [documentsDirectory stringByAppendingPathComponent:@"test.csv"];
    
    [self createPDFfromUIView:displayTableView saveToDocumentsWithFileName:ReportsPath];
    
}

-(void)createPDFfromUIView:(UITableView *)aView saveToDocumentsWithFileName:(NSString*)aFilename
{
    // Creates a mutable data object for updating with binary data, like a byte array
    NSMutableData *pdfData = [NSMutableData data];
    
    // Points the pdf converter to the mutable data object and to the UIView to be converted
    UIGraphicsBeginPDFContextToData(pdfData, aView.bounds, nil);
    UIGraphicsBeginPDFPage();
    CGContextRef pdfContext = UIGraphicsGetCurrentContext();
    
    
    // draws rect to the view and thus this is captured by UIGraphicsBeginPDFContextToData
    
    [aView.layer renderInContext:pdfContext];
    
    // remove PDF rendering context
    UIGraphicsEndPDFContext();
    
    // Retrieves the document directories from the iOS device
    
    NSArray *array = [NSArray arrayWithObjects:@"Date/Time,Store_ID",@"\nInv #",@"\nCust #",@"\nCashier ID",@"\nPM",@"\nTotal Cost",@"\nTotal Price",@"\nTax1",
                      @"\nTax2", @"\nTax3",@"\nGTotal",
                      @"\nGross", nil];
    
    NSString *docDir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
    NSString *filename=[NSString stringWithFormat:@"test.csv"];
    NSString *filePathLib = [NSString stringWithFormat:@"%@",[docDir stringByAppendingPathComponent:filename]];
    
    [[array componentsJoinedByString:@","] writeToFile:filePathLib atomically:YES encoding:NSUTF8StringEncoding error:NULL];
    
    
    
//    NSArray* documentDirectories = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask,YES);
//    
//    NSString* documentDirectory = [documentDirectories objectAtIndex:0];
//    NSString* documentDirectoryFilename = [documentDirectory stringByAppendingPathComponent:aFilename];
//    
//    // instructs the mutable data object to write its context to a file on disk
//    [pdfData writeToFile:documentDirectoryFilename atomically:YES];
//    // //NSLog(@"documentDirectoryFileName: %@",documentDirectoryFilename);
//    
//    
//    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
//    NSString *documentsDirectory = [paths objectAtIndex:0];
//    NSString *ReportsPath = [documentsDirectory stringByAppendingPathComponent:@"reports.pdf"];
//    
//    // //NSLog(@"reports path %@",ReportsPath);
    
}
-(void)printButtonClick: (id)sender
{
    
    UIGraphicsBeginImageContext(self->displayTableView.contentSize);
    [self->displayTableView.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    
    UIPrintInteractionController *printer = [UIPrintInteractionController sharedPrintController];
    printer.printingItem = viewImage;
    UIPrintInfo *info = [UIPrintInfo printInfo];
    //info.jobName= self.displayTableView;
    info.outputType = UIPrintInfoOutputGeneral;
    printer.printInfo = info;
    
    NSString * htmlString;
    
    UIMarkupTextPrintFormatter * htmlFormatter = [[UIMarkupTextPrintFormatter alloc]initWithMarkupText:htmlString];
    htmlFormatter.startPage = 0;
    htmlFormatter.contentInsets = UIEdgeInsetsMake(72, 72, 72, 72);
    printer.printFormatter = htmlFormatter;
    printer.showsPageRange= YES;
    
    UIPrintInteractionCompletionHandler completionHandler =
    ^(UIPrintInteractionController *pic, BOOL completed, NSError *error)
    {
        if (!completed && error)
            NSLog(@"FAILED! due to error in domain %@ with error code %u: %@",
                  error.domain, error.code, [error localizedDescription]);
    };
    printerButton = (UIButton *)sender;
    if(UIUserInterfaceIdiomPad == [[UIDevice currentDevice] userInterfaceIdiom]){
        [printer presentFromRect:printerButton.frame inView:self.view animated:YES completionHandler:completionHandler];
    }else {
        
        [printer presentAnimated:YES completionHandler:completionHandler];
    }
    
    
    UIAlertView * paymentAlert = [[UIAlertView alloc]initWithTitle:@"Payment Types" message:flashReportAlertStr delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK", nil];
    
    
    [paymentAlert show];

    
}
-(void)fromDateClick:(NSDate *)sender
{
    fromTFUp.text = [NSString stringWithFormat:@"%@",fromDate.date];
    fromDate.hidden=YES;
}
-(void)toDateClick:(NSDate *)sender
{
    toTFUp.text = [NSString stringWithFormat:@"%@", toDate.date];
    toDate.hidden=YES;
}
-(void)fromTimeClick
{
    fromTFDown.text = [NSString stringWithFormat:@"%@",fromTimePick.timeZone];
    fromTimePick.hidden=YES;

}
-(void)toTimeClick
{
    toTFDown.text = [NSString stringWithFormat:@"%@",toTimePick.timeZone];
    toTimePick.hidden=YES;

}
-(void)empIdBtnClick
{
     NSString *querySQL = [NSString stringWithFormat: @"SELECT employee_employee_id FROM employee_table"];
    NSMutableArray *emplArray=[[NSMutableArray alloc]init];
    [[DataBaseManager dataBaseManager]execute:querySQL resultsArray:emplArray];
   
    if (!empIdArray)
    empIdArray = [[NSMutableArray alloc]init];
    [empIdArray addObject:@"All"];
    @autoreleasepool {
        for (NSDictionary * myDict in emplArray)
        {
            NSString * catName= [myDict objectForKey:@"employee_employee_id"];
            [empIdArray addObject:catName];
        }
    }
    if (!empIdView)
    empIdView = [[UIView alloc]init];
    if (isLandScope)
    {
        empIdView .frame=CGRectMake(0, 0, 1024, 768);
    }else{
        empIdView.frame=CGRectMake(0, 0, 768, 1024);
        
    }
    [empIdView setBackgroundColor:[UIColor colorWithRed:10.0f/255.0f green:10.0f/255.0f blue:10.0f/255.0f alpha:0.7f/1.0f]];
    [self.view addSubview:empIdView];
    
    //[self.view addSubview:departmentPopUp];
    if (!empIDTableView)
    empIDTableView=[[UITableView alloc]init];
    empIDTableView.frame=CGRectMake(100,200 ,empIdView.frame.size.width-200, empIdView.frame.size.height-400);
    empIDTableView.backgroundColor=[UIColor whiteColor];
    empIDTableView.delegate = self;
    empIDTableView.dataSource = self;
    empIDTableView.scrollEnabled = YES;
    //departmentTV.hidden=YES;
    [empIDTableView.layer setBorderWidth: 2.0];
    [empIDTableView.layer setCornerRadius:8.0f];
    //[titlesdata_table.layer setMasksToBounds:YES];
    [empIDTableView.layer setBorderColor:[[UIColor grayColor] CGColor]];
    [empIdView addSubview:empIDTableView];
}
-(void)orderStatusBtnClick
{
    if (!orderArray)
    orderArray=[[NSMutableArray alloc]initWithObjects:@"hold",@"void",@"complete",nil];
    if (!orderView)
    orderView = [[UIView alloc]init];
    if (isLandScope){
        orderView.frame = CGRectMake(0, 0, 1024, 768);
    }else{
        orderView .frame = CGRectMake(0, 0, 768, 1024);
    }
    
    [orderView setBackgroundColor:[UIColor colorWithRed:10.0f/255.0f green:10.0f/255.0f blue:10.0f/255.0f alpha:0.7f/1.0f]];
    [self.view addSubview:orderView];
     if (!orderTableView)
    orderTableView = [[UITableView alloc]initWithFrame:CGRectMake(100,200 ,orderView.frame.size.width-200, orderView.frame.size.height-400)];
    orderTableView.backgroundColor=[UIColor whiteColor];
    orderTableView.delegate = self;
    orderTableView.dataSource = self;
    orderTableView.scrollEnabled = YES;
    //paymentTV.hidden=YES;
    [orderTableView.layer setBorderWidth: 2.0];
    //[titlesdata_table.layer setCornerRadius:8.0f];
    //[titlesdata_table.layer setMasksToBounds:YES];
    [orderTableView.layer setBorderColor:[[UIColor grayColor] CGColor]];
    [orderView addSubview:orderTableView];
}
-(void)customerBtnClick
{
    
    
     if (!customerArray)
    customerArray = [[NSMutableArray alloc]init];
    
    NSString *querySQL5 = [NSString stringWithFormat: @"SELECT store_id FROM store_details"];
    NSMutableArray *storesArray=[[NSMutableArray alloc]init];
    [[DataBaseManager dataBaseManager]execute:querySQL5 resultsArray:storesArray];
    
    [customerArray addObject:@"All"];
    @autoreleasepool {
        for (NSDictionary * myDict in storesArray)
        {
            NSString * catName= [myDict objectForKey:@"store_id"];
            [customerArray addObject:catName];
        }
    }
    if (!customerView)
    customerView = [[UIView alloc]init];
    if (isLandScope){
        customerView .frame= CGRectMake(0, 0, 1024, 768);
    }else{
        customerView.frame= CGRectMake(0, 0, 768, 1024);
    }
    [customerView setBackgroundColor:[UIColor colorWithRed:10.0f/255.0f green:10.0f/255.0f blue:10.0f/255.0f alpha:0.7f/1.0f]];
    [self.view addSubview:customerView];
    
    //[self.view addSubview:departmentPopUp];
    if (!customerTableView)
    customerTableView=[[UITableView alloc]init];
    customerTableView.frame=CGRectMake(100,200 ,customerView.frame.size.width-200, customerView.frame.size.height-400);
    customerTableView.backgroundColor=[UIColor whiteColor];
    customerTableView.delegate = self;
    customerTableView.dataSource = self;
    customerTableView.scrollEnabled = YES;
    //departmentTV.hidden=YES;
    [customerTableView.layer setBorderWidth: 2.0];
    [customerTableView.layer setCornerRadius:8.0f];
    //[titlesdata_table.layer setMasksToBounds:YES];
    [customerTableView.layer setBorderColor:[[UIColor grayColor] CGColor]];
    [customerView addSubview:customerTableView];
    

}

-(void)departmentClick
{
    
  
    
    NSString *deptsQuery = [NSString stringWithFormat:@"SELECT department_id FROM department_details"];
    NSMutableArray *deptsArray=[[NSMutableArray alloc]init];
    [[DataBaseManager dataBaseManager]execute:deptsQuery resultsArray:deptsArray];
    if (!departmentNamesArray)
     departmentNamesArray = [[NSMutableArray alloc]init];
    if ([deptsArray count]>0)
    {
        for (NSDictionary *myDict in deptsArray)
        {
            
            NSString *catname=[myDict objectForKey:@"department_id"];
            
            [departmentNamesArray addObject:catname];
            //// //NSLog(@"the departmentNames Array is %@", departmentNamesArray);
        }
        // Dept=[departmentNamesArray objectAtIndex:0];
    }

    if (!departmentPopUp)
    departmentPopUp = [[UIView alloc]init];
    if (isLandScope)
    {
        departmentPopUp.frame =CGRectMake(0, 0, 1024, 768);
    }else{
         departmentPopUp.frame =CGRectMake(0, 0, 768, 1024);
    }
    [departmentPopUp setBackgroundColor:[UIColor colorWithRed:10.0f/255.0f green:10.0f/255.0f blue:10.0f/255.0f alpha:0.7f/1.0f]];
    [self.view addSubview:departmentPopUp];
    
    //[self.view addSubview:departmentPopUp];
    if (!departmentTV)
    departmentTV=[[UITableView alloc]init];
    departmentTV.frame=CGRectMake(100,200 ,departmentPopUp.frame.size.width-200, departmentPopUp.frame.size.height-400);
    departmentTV.backgroundColor=[UIColor whiteColor];
    departmentTV.delegate = self;
    departmentTV.dataSource = self;
    departmentTV.scrollEnabled = YES;
    //departmentTV.hidden=YES;
    [departmentTV.layer setBorderWidth: 2.0];
    [departmentTV.layer setCornerRadius:8.0f];
    //[titlesdata_table.layer setMasksToBounds:YES];
    [departmentTV.layer setBorderColor:[[UIColor grayColor] CGColor]];
    [departmentPopUp addSubview:departmentTV];
    
}
-(void)ReportTypeBtnClick
{
    //@"Flash Reports",
     if (!ReportTypesArray)
      ReportTypesArray=[[NSMutableArray alloc]initWithObjects:@"Invoice Total Reports",@"Payment Type Reports",@"Department Wise reports", @"Employee Shift Reports",@"Flash Reports",@"Detailed Daily Reports",nil];
    if (!ReportTypeView)
    ReportTypeView = [[UIView alloc]init];
    if (isLandScope)
    {
        ReportTypeView.frame = CGRectMake(0, 0, 1024, 768);
    }else{
        ReportTypeView.frame= CGRectMake(0, 0, 768, 1024);
    }
    [ReportTypeView setBackgroundColor:[UIColor colorWithRed:10.0f/255.0f green:10.0f/255.0f blue:10.0f/255.0f alpha:0.7f/1.0f]];
    [self.view addSubview:ReportTypeView];
     if (!ReportTypeTable)
    ReportTypeTable = [[UITableView alloc]initWithFrame:CGRectMake(100,200 ,ReportTypeView.frame.size.width-200, ReportTypeView.frame.size.height-400)];
    ReportTypeTable.backgroundColor=[UIColor whiteColor];
    ReportTypeTable.delegate = self;
    ReportTypeTable.dataSource = self;
    ReportTypeTable.scrollEnabled = YES;
    //paymentTV.hidden=YES;
    [ReportTypeTable.layer setBorderWidth: 2.0];
    //[titlesdata_table.layer setCornerRadius:8.0f];
    //[titlesdata_table.layer setMasksToBounds:YES];
    [ReportTypeTable.layer setBorderColor:[[UIColor grayColor] CGColor]];
    [ReportTypeView addSubview:ReportTypeTable];
}

-(void)paymentClick
{
    
 
 
    if (!paymentArray)
    paymentArray=[[NSMutableArray alloc]initWithObjects:@"All",@"Cash",@"Cheque",@"Card", nil];
    if (!paymentPopUp)
    paymentPopUp = [[UIView alloc]init];
    if (isLandScope)
    {
         paymentPopUp.frame=CGRectMake(0, 0, 1024, 768);
    }else{
         paymentPopUp.frame= CGRectMake(0, 0, 768, 1024);
    }
    [paymentPopUp setBackgroundColor:[UIColor colorWithRed:10.0f/255.0f green:10.0f/255.0f blue:10.0f/255.0f alpha:0.7f/1.0f]];
    [self.view addSubview:paymentPopUp];
     if (!paymentTV)
    paymentTV = [[UITableView alloc]initWithFrame:CGRectMake(100,200 ,paymentPopUp.frame.size.width-200, paymentPopUp.frame.size.height-400)];
    paymentTV.backgroundColor=[UIColor whiteColor];
    paymentTV.delegate = self;
    paymentTV.dataSource = self;
    paymentTV.scrollEnabled = YES;
    //paymentTV.hidden=YES;
    [paymentTV.layer setBorderWidth: 2.0];
    //[titlesdata_table.layer setCornerRadius:8.0f];
    //[titlesdata_table.layer setMasksToBounds:YES];
    [paymentTV.layer setBorderColor:[[UIColor grayColor] CGColor]];
    [paymentPopUp addSubview:paymentTV];

}

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
    
    if(textField == searchField)
    {
        SearchlistTable.hidden = NO;
        NSString *substring = [NSString stringWithString:textField.text];
        substring = [substring stringByReplacingCharactersInRange:range withString:string];
        [self searchAutocompleteEntriesWithSubstring:substring];
        
    }
    return YES;
    
}
- (void)searchAutocompleteEntriesWithSubstring:(NSString *)substring
{
    
    // Put anything that starts with this substring into the autocompleteUrls array
    // The items in this array is what will show up in the table view
    if ([substring length]>=2){
        [SearchDataArray removeAllObjects];
        
        for(NSMutableString *curString in pastDataArray)
        {
            NSRange titleResultsRange = [curString rangeOfString:substring options:NSCaseInsensitiveSearch];
            
            if (titleResultsRange.length > 0)
                [SearchDataArray addObject:curString];
            
        }
        
        [SearchlistTable reloadData];
        
    }else{
        SearchlistTable.hidden=YES;
    }
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (tableView==displayTableView){
        if (indexPath.row==0){
            
            return 50;
        }else{
            
            return 80;
        }
    }else if (tableView==invoiceTableView){
        if (indexPath.row==0){
            
            return 50;
        }else{
             return 80;
        }
    }else{
        return 50;
        
    }

    return YES;
   
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    // This will create a "invisible" footer
    return 0.01f;
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    return [UIView new];
    
    // If you are not using ARC:
    // return [[UIView new] autorelease];
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (tableView == departmentTV){
        return [departmentNamesArray count];
        
    }else if (tableView == customerTableView){
        return [customerArray count];
    }else if (tableView ==  paymentTV){
        return [paymentArray count];
        
    }else if (tableView == displayTableView){
        return [loginEmp count]+1;
    }else if (tableView == invoiceTableView){
        return [invoiceitem count]+1;
        
    }else if (tableView==SearchlistTable){
        return [SearchDataArray count];
    }else if (tableView==ReportTypeTable){
        return [ReportTypesArray count];
    }else if (tableView== orderTableView){
        return [orderArray count];
    }else if (tableView == empIDTableView){
        return [empIdArray count];
        
    }

    return YES;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    
    if (tableView == invoiceTableView){
        
        InvoiceCell  *cell = (InvoiceCell *)[tableView dequeueReusableCellWithIdentifier:@"CellIdentifier"];
        
        if(!cell) {
            [[NSBundle mainBundle] loadNibNamed:@"InvoiceCell" owner:self options:nil];
            cell = invoiceCell;
        }
        
        // // //NSLog(@"Dict :-%@",dict);
        if (indexPath.row==0){
            cell.itemID_TextView.text = @"ItemID";
            cell.Discount_TextView.text =@"Discount";
            cell.tax_TextView.text =@"Tax";
            cell.cost_TextView.text =@"Cost";
            cell.avgCost_TextView.text =@"AvgCost";
            cell.qty_TextView.text =@"Qty";
            cell.date_TextView.text =@"Date";
            
            cell.itemID_TextView.textColor=[UIColor blackColor];
            cell.Discount_TextView.textColor=[UIColor blackColor];
            cell.tax_TextView.textColor=[UIColor blackColor];
            cell.cost_TextView.textColor=[UIColor blackColor];
            cell.avgCost_TextView.textColor=[UIColor blackColor];
            cell.qty_TextView.textColor=[UIColor blackColor];
            cell.date_TextView.textColor=[UIColor blackColor];
            cell.contentView.backgroundColor=[UIColor colorWithRed:200.0f/255.0f green:200.0f/255.0f blue:200.0f/255.0f alpha:1.0f];

        }else{
            cell.itemID_TextView.text = [invoiceitem objectAtIndex:indexPath.row-1];
            cell.Discount_TextView.text =[invoiceDis objectAtIndex:indexPath.row-1];
            cell.tax_TextView.text =[invoiceTotalTax objectAtIndex:indexPath.row-1];
            cell.cost_TextView.text =[invPriceChange objectAtIndex:indexPath.row-1];
            cell.avgCost_TextView.text =[invPriceChange objectAtIndex:indexPath.row-1];
            cell.qty_TextView.text =[invinItemQut objectAtIndex:indexPath.row-1];
            cell.date_TextView.text =[invCreatedTs objectAtIndex:indexPath.row-1];
            
            cell.itemID_TextView.textColor=[UIColor whiteColor];
            cell.Discount_TextView.textColor=[UIColor whiteColor];
            cell.tax_TextView.textColor=[UIColor whiteColor];
            cell.cost_TextView.textColor=[UIColor whiteColor];
            cell.avgCost_TextView.textColor=[UIColor whiteColor];
            cell.qty_TextView.textColor=[UIColor whiteColor];
            cell.date_TextView.textColor=[UIColor whiteColor];
            
            if (indexPath.row%2==0){
                
                cell.contentView.backgroundColor=[UIColor colorWithRed:64.0f/255.0f green:96.0f/255.0f blue:120.0f/255.0f alpha:1.0f];
            }else{
                cell.contentView.backgroundColor=[UIColor colorWithRed:56.0f/255.0f green:104.0f/255.0f blue:128.0f/255.0f alpha:1.0f];
            }
            
        }

        return cell;
        
    }else if (tableView == displayTableView){
        
        ReportsEmployeeCell  *cell = (ReportsEmployeeCell *)[tableView dequeueReusableCellWithIdentifier:@"CellIdentifier"];
        
        if(!cell) {
            [[NSBundle mainBundle] loadNibNamed:@"ReportsEmployeeCell" owner:self options:nil];
            cell = reportsEmployeeCell;
        }
        
        // // //NSLog(@"Dict :-%@",dict);
        if (indexPath.row==0){
            cell.empID_TextView.text = @"EmpID";
            cell.EmpName_TextView.text =@"EmpName";
            cell.logIntime_TextView.text =@"LoginTime";
            cell.logOuttime_TextView.text =@"LogoutTime";
            cell.time_TextView.text =@"Time";
            cell.wages_TextView.text =@"Wages";
           
            
            cell.empID_TextView.textColor=[UIColor blackColor];
            cell.EmpName_TextView.textColor=[UIColor blackColor];
            cell.logIntime_TextView.textColor=[UIColor blackColor];
            cell.logOuttime_TextView.textColor=[UIColor blackColor];
            cell.time_TextView.textColor=[UIColor blackColor];
            cell.wages_TextView.textColor=[UIColor blackColor];
           
            cell.contentView.backgroundColor=[UIColor colorWithRed:200.0f/255.0f green:200.0f/255.0f blue:200.0f/255.0f alpha:1.0f];
        
        }else{
            cell.empID_TextView.text = [loginEmp objectAtIndex:indexPath.row-1];
            cell.EmpName_TextView.text =[loginEmpID objectAtIndex:indexPath.row-1];
            cell.logIntime_TextView.text =[empLoginTime objectAtIndex:indexPath.row-1];
            cell.logOuttime_TextView.text =[empLogoutTime objectAtIndex:indexPath.row-1];
            cell.time_TextView.text =[TimesArray objectAtIndex:indexPath.row-1];
            cell.wages_TextView.text =[wages objectAtIndex:indexPath.row-1];
            
            cell.empID_TextView.textColor=[UIColor whiteColor];
            cell.EmpName_TextView.textColor=[UIColor whiteColor];
            cell.logIntime_TextView.textColor=[UIColor whiteColor];
            cell.logOuttime_TextView.textColor=[UIColor whiteColor];
            cell.time_TextView.textColor=[UIColor whiteColor];
            cell.wages_TextView.textColor=[UIColor whiteColor];
 
            
            if (indexPath.row%2==0){
                
                cell.contentView.backgroundColor=[UIColor colorWithRed:64.0f/255.0f green:96.0f/255.0f blue:120.0f/255.0f alpha:1.0f];
            }else
            {
                cell.contentView.backgroundColor=[UIColor colorWithRed:56.0f/255.0f green:104.0f/255.0f blue:128.0f/255.0f alpha:1.0f];
                
            }
            
        }
        
        return cell;
        
    }else{
    static NSString *CellIdentifier = @"Cell";
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    
        if(!cell) {
            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:nil];
        }

    if (tableView == orderTableView) {
        cell.textLabel.text=[orderArray objectAtIndex:indexPath.row];
        cell.textLabel.textAlignment=NSTextAlignmentCenter;
        
    }else if (tableView == customerTableView) {
        cell.textLabel.text=[customerArray objectAtIndex:indexPath.row];
        cell.textLabel.textAlignment=NSTextAlignmentCenter;
        
    }else if (tableView == empIDTableView){
        cell.textLabel.text=[empIdArray objectAtIndex:indexPath.row];
        cell.textLabel.textAlignment=NSTextAlignmentCenter;

    }else if (tableView== ReportTypeTable){
        
        cell.textLabel.text=[ReportTypesArray objectAtIndex:indexPath.row];
        cell.textLabel.textAlignment=NSTextAlignmentCenter;
    }else if (tableView== paymentTV){
        
        cell.textLabel.text=[paymentArray objectAtIndex:indexPath.row];
        cell.textLabel.textAlignment=NSTextAlignmentCenter;
    }else if (tableView== SearchlistTable){
        cell.textLabel.text=[SearchDataArray objectAtIndex:indexPath.row];
        cell.textLabel.textAlignment=NSTextAlignmentCenter;
        
    }else if (tableView== departmentTV){
                
        cell.textLabel.text=[departmentNamesArray objectAtIndex:indexPath.row];
        cell.textLabel.textAlignment=NSTextAlignmentCenter;
    }
    
   
    return cell;
  }
}
-(void) reportViewremove
{
    [ReportTypesArray removeAllObjects];
    ReportTypesArray=Nil;
  
    NSArray *mainArray = ReportTypeView.subviews;
    for (int i = 0; i<[mainArray count]; i++) {
        UIView *vi =[mainArray objectAtIndex:i];
        [vi removeFromSuperview];
        vi = nil;
    }
     [ReportTypeView removeFromSuperview];
}
-(void) paymenttypeViewremove{
   [paymentArray removeAllObjects], paymentArray=Nil;
   
    NSArray *mainArray = paymentPopUp.subviews;
    for (int i = 0; i<[mainArray count]; i++) {
        UIView *vi =[mainArray objectAtIndex:i];
        [vi removeFromSuperview];
        vi = nil;
    }
    [paymentPopUp removeFromSuperview];
}
-(void) employeeViewremove{
  
    
    [empIdArray removeAllObjects], empIdArray=Nil;
    
    NSArray *mainArray = empIdView.subviews;
    for (int i = 0; i<[mainArray count]; i++) {
        UIView *vi =[mainArray objectAtIndex:i];
        [vi removeFromSuperview];
        vi = nil;
    }
    [empIdView removeFromSuperview];
}
-(void) customerViewremove{
    [customerArray removeAllObjects], customerArray=Nil;
    
    NSArray *mainArray = customerView.subviews;
    for (int i = 0; i<[mainArray count]; i++) {
        UIView *vi =[mainArray objectAtIndex:i];
        [vi removeFromSuperview];
        vi = nil;
    }
    [customerView removeFromSuperview];
}
-(void) departmentViewremove{
   
    
    [departmentNamesArray removeAllObjects], departmentNamesArray=Nil;
    
    NSArray *mainArray = departmentPopUp.subviews;
    for (int i = 0; i<[mainArray count]; i++) {
        UIView *vi =[mainArray objectAtIndex:i];
        [vi removeFromSuperview];
        vi = nil;
    }
    [departmentPopUp removeFromSuperview];
}
-(void) orderViewremove{
    [orderArray removeAllObjects], orderArray=Nil;
    
    NSArray *mainArray = orderView.subviews;
    for (int i = 0; i<[mainArray count]; i++) {
        UIView *vi =[mainArray objectAtIndex:i];
        [vi removeFromSuperview];
        vi = nil;
    }
    [orderView removeFromSuperview];
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (tableView == orderTableView){

        NSString *selectedstr=[orderArray objectAtIndex:indexPath.row];
        [orderStatusBtn setTitle:selectedstr forState:UIControlStateNormal];
        [self orderViewremove];
        
    }else if (tableView == customerTableView){
     
        
        NSString *selectedstr=[customerArray objectAtIndex:indexPath.row];
        [customerIdBtn setTitle:selectedstr forState:UIControlStateNormal];
           [self customerViewremove];
        
    }else if (tableView == empIDTableView){
      
        
        NSString *selectedstr=[empIdArray objectAtIndex:indexPath.row];
        [empIdBtn setTitle:selectedstr forState:UIControlStateNormal];
        [self employeeViewremove];
    }else if (tableView==departmentTV){

        NSString *selectedstr=[departmentNamesArray objectAtIndex:indexPath.row];
        [departmentButton setTitle:selectedstr forState:UIControlStateNormal];
        [self departmentViewremove];
        
    }else if (tableView==paymentTV){
        NSString *selectedstr=[paymentArray objectAtIndex:indexPath.row];
        [paymentButton setTitle:selectedstr forState:UIControlStateNormal];
         [self paymenttypeViewremove];
        
    }else if (tableView==SearchlistTable){
        
        SearchlistTable.hidden=YES;
        
        NSString *selectedstr=[SearchDataArray objectAtIndex:indexPath.row];
        
        searchField.text=selectedstr;
    }else if (tableView==ReportTypeTable){
      
        NSString *selectedstr=[ReportTypesArray objectAtIndex:indexPath.row];
        [ReporttypeBtn setTitle:selectedstr forState:UIControlStateNormal];
          [self reportViewremove];
        if ([selectedstr isEqualToString:@"Flash Reports"]){
            paymentButton.enabled=NO;
            departmentButton.enabled=NO;
            
            orderStatusBtn.enabled=NO;
            empIdBtn.enabled=NO;
            customerIdBtn.enabled=NO;
            
        }else if ([selectedstr isEqualToString:@"Invoice Total Reports"]){
            
            //[invoiceTableView reloadData];
            paymentButton.enabled=YES;
            orderStatusBtn.enabled=YES;
           
            
            departmentButton.enabled=NO;
            
            empIdBtn.enabled=NO;
            customerIdBtn.enabled=YES;
            
        }else if ([selectedstr isEqualToString:@"Payment Type Reports"]){
            
            departmentButton.enabled=NO;
            orderStatusBtn.enabled=NO;
            empIdBtn.enabled=NO;
            customerIdBtn.enabled=NO;
            
        }else if ([selectedstr isEqualToString:@"Department Wise reports"]){
            paymentButton.enabled=NO;
            orderStatusBtn.enabled=NO;
            empIdBtn.enabled=NO;
            customerIdBtn.enabled=NO;
        
             departmentButton.enabled=YES;
            
        }else if ([selectedstr isEqualToString:@"Employee Shift Reports"]){
              empIdBtn.enabled=YES;
            paymentButton.enabled=NO;
            departmentButton.enabled=NO;
            orderStatusBtn.enabled=NO;
            customerIdBtn.enabled=NO;
            
        }else if ([selectedstr isEqualToString:@"Detailed Daily Reports"]){
            paymentButton.enabled=NO;
            departmentButton.enabled=NO;
            
            //orderStatusBtn.enabled=NO;
            empIdBtn.enabled=NO;
            customerIdBtn.enabled=NO;
            
        }
        
    }
    
}
-(void)textFieldDidBeginEditing:(UITextField *)textField
{
    
    if (textField == fromTFUp){
        //[blueView addSubview:_fromDate];
        
        if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad){
            
            int totalwidth=self.view.frame.size.width;
            
            int leftpos= (totalwidth/2)-(350/2);
            
            CGRect pickerframe = CGRectMake(leftpos-20,200,500, 500);
            if (!datePicker)
            datePicker = [[UIDatePicker alloc] init];
            datePicker.frame=pickerframe;
            [datePicker setDatePickerMode:UIDatePickerModeDate];
            [datePicker setBackgroundColor:[UIColor whiteColor]];
            [datePicker addTarget:self action:@selector(pickerChanged:) forControlEvents:UIControlEventValueChanged];
            if (!subview1)
            subview1=[[UIView alloc]init];
            if (isLandScope)
            {
              subview1.frame=CGRectMake(0, 0,1024, 768);
            }else{
               subview1.frame=CGRectMake(0, 0,768, 1024);
           }
            subview1.backgroundColor=[UIColor colorWithRed:10.0f/255.0f green:10.0f/255.0f blue:10.0f/255.0f alpha:0.7f/1.0f];
             if (!btn1)
            btn1=[UIButton buttonWithType:UIButtonTypeCustom];
            [btn1 setFrame:CGRectMake(leftpos+200,500, 50, 30)];
            [btn1 setTitle:@"ok" forState:UIControlStateNormal];
            btn1.backgroundColor=[UIColor whiteColor];
            [btn1 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
            [btn1 setBackgroundImage:[UIImage imageNamed:@"greenbutton.png"] forState:UIControlStateNormal];
            [btn1 addTarget:self action:@selector(dateselected) forControlEvents:UIControlEventTouchUpInside];
            [subview1 addSubview:btn1];
            
            [subview1 addSubview:datePicker];
            [self.view addSubview:subview1];
            datePicker.tag=1;
            
        }
        // //NSLog(@"1st TextFiled");
        
      [textField resignFirstResponder];
        
    }else if (textField == toTFUp){
        int totalwidth=self.view.frame.size.width;
        
        int leftpos= (totalwidth/2)-(350/2);
        CGRect pickerframe = CGRectMake(leftpos-20,200, 500, 500);
        if (!datePicker2)
        datePicker2 = [[UIDatePicker alloc] init];
        datePicker2.frame=pickerframe;
        [datePicker2 setDatePickerMode:UIDatePickerModeDate];
        [datePicker2 setBackgroundColor:[UIColor whiteColor]];
        [datePicker2 addTarget:self action:@selector(pickerChanged:) forControlEvents:UIControlEventValueChanged];
        if (!subview1)
        subview1=[[UIView alloc]init];
        if (isLandScope){
            subview1.frame=CGRectMake(0, 0,1024, 768);
        }else{
            subview1.frame=CGRectMake(0, 0,768, 1024);
        }
        subview1.backgroundColor=[UIColor colorWithRed:10.0f/255.0f green:10.0f/255.0f blue:10.0f/255.0f alpha:0.7f/1.0f];
         if (!btn1)
        btn1=[UIButton buttonWithType:UIButtonTypeCustom];
        [btn1 setFrame:CGRectMake(leftpos+200,500, 50, 30)];
        [btn1 setTitle:@"ok" forState:UIControlStateNormal];
        btn1.backgroundColor=[UIColor whiteColor];
        [btn1 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
       [btn1 setBackgroundImage:[UIImage imageNamed:@"greenbutton.png"] forState:UIControlStateNormal];
        [btn1 addTarget:self action:@selector(dateselected) forControlEvents:UIControlEventTouchUpInside];
        [subview1 addSubview:btn1];
        
        [subview1 addSubview:datePicker2];
        [self.view addSubview:subview1];
        datePicker2.tag=2;
        
        // //NSLog(@"2nd TextField");
        [textField resignFirstResponder];
    }else if (textField == fromTFDown)
    {
        //[blueView addSubview:_fromDate];
        
        if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
        {
            
            int totalwidth=self.view.frame.size.width;
            
            int leftpos= (totalwidth/2)-(350/2);
            
            CGRect pickerframe = CGRectMake(leftpos-20,200,500, 500);
             if (!datePicker3)
            datePicker3 = [[UIDatePicker alloc] init];
            datePicker3.frame=pickerframe;
            [datePicker3 setDatePickerMode:UIDatePickerModeTime];
            [datePicker3 setBackgroundColor:[UIColor whiteColor]];
            [datePicker3 addTarget:self action:@selector(pickerChanged:) forControlEvents:UIControlEventValueChanged];
            if (!subview1)
            subview1=[[UIView alloc]init];
            if (isLandScope){
                subview1.frame=CGRectMake(0, 0,1024, 768);
            }else{
                subview1.frame=CGRectMake(0, 0,768, 1024);
            }
            subview1.backgroundColor=[UIColor colorWithRed:10.0f/255.0f green:10.0f/255.0f blue:10.0f/255.0f alpha:0.7f/1.0f];
             if (!btn1)
            btn1=[UIButton buttonWithType:UIButtonTypeCustom];
            [btn1 setFrame:CGRectMake(leftpos+200,500, 50, 30)];
            [btn1 setTitle:@"ok" forState:UIControlStateNormal];
            btn1.backgroundColor=[UIColor whiteColor];
            [btn1 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
            [btn1 setBackgroundImage:[UIImage imageNamed:@"greenbutton.png"] forState:UIControlStateNormal];
            [btn1 addTarget:self action:@selector(dateselected) forControlEvents:UIControlEventTouchUpInside];
            [subview1 addSubview:btn1];
            
            [subview1 addSubview:datePicker3];
            [self.view addSubview:subview1];
            datePicker3.tag=3;
            
        }
        // //NSLog(@"1st TextFiled");
        [textField resignFirstResponder];
    }else if (textField == toTFDown){
        int totalwidth=self.view.frame.size.width;
        
        int leftpos= (totalwidth/2)-(350/2);
        CGRect pickerframe = CGRectMake(leftpos-20,200, 500, 500);
        if (!datePicker4)
        datePicker4 = [[UIDatePicker alloc] init];
        datePicker4.frame=pickerframe;
        [datePicker4 setDatePickerMode:UIDatePickerModeTime];
        [datePicker4 setBackgroundColor:[UIColor whiteColor]];
        [datePicker4 addTarget:self action:@selector(pickerChanged:) forControlEvents:UIControlEventValueChanged];
        if (!subview1)
        subview1=[[UIView alloc]init];
        if (isLandScope){
            subview1.frame=CGRectMake(0, 0,1024, 768);
        }else{
            subview1.frame=CGRectMake(0, 0,768, 1024);
        }
        subview1.backgroundColor=[UIColor colorWithRed:10.0f/255.0f green:10.0f/255.0f blue:10.0f/255.0f alpha:0.7f/1.0f];
        if (!btn1)
        btn1=[UIButton buttonWithType:UIButtonTypeCustom];
        [btn1 setFrame:CGRectMake(leftpos+200,500, 50, 30)];
        [btn1 setTitle:@"ok" forState:UIControlStateNormal];
        btn1.backgroundColor=[UIColor whiteColor];
        [btn1 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [btn1 setBackgroundImage:[UIImage imageNamed:@"greenbutton.png"] forState:UIControlStateNormal];
        [btn1 addTarget:self action:@selector(dateselected) forControlEvents:UIControlEventTouchUpInside];
        [subview1 addSubview:btn1];
        
        [subview1 addSubview:datePicker4];
        [self.view addSubview:subview1];
        datePicker4.tag=4;
        
        // //NSLog(@"2nd TextField");
        [textField resignFirstResponder];
    }
    
    
}
-(void)dateselected
{
    [subview1 removeFromSuperview];
    
}
-(void)pickerChanged:(id)sender
{
    if ([sender tag]==1)
    {
        NSDate *selectedDate = datePicker.date;
        NSDateFormatter *formatter;
        if (!formatter)
        formatter = [[NSDateFormatter alloc] init];
        [formatter setDateStyle:NSDateFormatterShortStyle];
        [formatter setTimeStyle:NSDateFormatterNoStyle];
        [formatter setDateFormat:@"yyyy-MM-dd"];
        NSString *datestr=[formatter stringFromDate:selectedDate];
        [fromTFUp setText:datestr];
        //[alert dismissWithClickedButtonIndex:1 animated:YviewES];
     }
    else if ([sender tag]==2)
    {
        NSDate *selectedDate = datePicker2.date;
        NSDateFormatter *formatter;
        if (!formatter)
        formatter = [[NSDateFormatter alloc] init];
        [formatter setDateStyle:NSDateFormatterShortStyle];
        [formatter setTimeStyle:NSDateFormatterNoStyle];
        [formatter setDateFormat:@"yyyy-MM-dd"];
        NSString *datestr=[formatter stringFromDate:selectedDate];
        [toTFUp setText:datestr];
        
    }
   else if ([sender tag]==3)
    {
        NSDate *selectedDate = datePicker3.date;
        NSDateFormatter *formatter;
        if (!formatter)
        formatter = [[NSDateFormatter alloc] init];
        [formatter setDateStyle:NSDateFormatterShortStyle];
        [formatter setTimeStyle:NSDateFormatterNoStyle];
        [formatter setDateFormat:@"HH:mm:ss"];
        NSString *datestr=[formatter stringFromDate:selectedDate];
        [fromTFDown setText:datestr];
        //[alert dismissWithClickedButtonIndex:1 animated:YviewES];
    }
    else if ([sender tag]==4)
    {
        NSDate *selectedDate = datePicker4.date;
        NSDateFormatter *formatter;
        if (!formatter)
        formatter = [[NSDateFormatter alloc] init];
        [formatter setDateStyle:NSDateFormatterShortStyle];
        [formatter setTimeStyle:NSDateFormatterNoStyle];
        [formatter setDateFormat:@"HH:mm:ss"];
        NSString *datestr=[formatter stringFromDate:selectedDate];
        [toTFDown setText:datestr];
        
    }
    
}
-(void)goButtonClick
{
    PrinterIpsArray=nil;
    [printcharArray    removeAllObjects];
    [FontsArray    removeAllObjects];
    [AlignsArray    removeAllObjects];
    languagesArray =nil;
    [WidthsArray    removeAllObjects];
   [HeightsArray    removeAllObjects];
    [unitsArray    removeAllObjects];
    [boldsArray    removeAllObjects];
    [UnderlinesArray    removeAllObjects];
    [XpossArray    removeAllObjects];
    [spacingsArray    removeAllObjects];
    [printernamesArray    removeAllObjects];
    [IpAddsArray    removeAllObjects];
    [DBPrintertypesArray removeAllObjects];
    
    [loginEmp    removeAllObjects];
    [loginEmpID    removeAllObjects];
    [empLoginTime    removeAllObjects];
    [empLogoutTime    removeAllObjects];
    [diffMin    removeAllObjects];
    [diffHours    removeAllObjects];
    [wages    removeAllObjects];
    [sessionId    removeAllObjects];
    [uniqueId    removeAllObjects];
    [createdTimeStamp removeAllObjects];
    [modifiedTimeStamp    removeAllObjects];
    [serverLocal    removeAllObjects];
    
    [invoiceitem   removeAllObjects];
    [invoiceDis    removeAllObjects];
    [invoiceTotalTax    removeAllObjects];
    [invItemName    removeAllObjects];
    [invItemDisp    removeAllObjects];
   [invPriceChange    removeAllObjects];
    [invAvgCost    removeAllObjects];
    [invinItemQut    removeAllObjects];
    [invID    removeAllObjects];
    [invUniqueID    removeAllObjects];
    [invCreatedTs removeAllObjects];
    [invPaymentType    removeAllObjects];
    [invInDept    removeAllObjects];
    [invVendor    removeAllObjects];
    [invStoreId    removeAllObjects];
    [invStatus    removeAllObjects];
     
    PrinterIpsArray=nil;
    printcharArray = nil;
    FontsArray = nil;
    AlignsArray = nil;
    languagesArray =nil;
    WidthsArray = nil;
    HeightsArray = nil;
    unitsArray = nil;
    boldsArray = nil;
    UnderlinesArray = nil;
    XpossArray = nil;
    spacingsArray = nil;
    printernamesArray = nil;
    IpAddsArray = nil;
    DBPrintertypesArray=nil;
    
    loginEmp = nil;
    loginEmpID = nil;
    empLoginTime = nil;
    empLogoutTime = nil;
    diffMin = nil;
    diffHours = nil;
    wages = nil;
    sessionId = nil;
    uniqueId = nil;
    createdTimeStamp =nil;
    modifiedTimeStamp = nil;
    serverLocal = nil;
    
    invoiceitem= nil;
    invoiceDis = nil;
    invoiceTotalTax = nil;
    invItemName = nil;
    invItemDisp = nil;
    invPriceChange = nil;
    invAvgCost = nil;
    invinItemQut = nil;
    invID = nil;
    invUniqueID = nil;
    invCreatedTs =nil;
    invPaymentType = nil;
    invInDept = nil;
    invVendor = nil;
    invStoreId = nil;
    invStatus = nil;
    
    [self GetPrinterDataMethod];
    
    NSString * selectSql;
    NSString * deptID= [NSString stringWithFormat:@"%@",departmentButton.titleLabel.text];
    NSString *Pay=[NSString stringWithFormat:@"%@",paymentButton.titleLabel.text];
    
    NSString * orderStatus= [NSString stringWithFormat:@"%@",orderStatusBtn.titleLabel.text];
    
    
    NSString *paymentsReports= [NSString stringWithFormat:@"%@",ReporttypeBtn.titleLabel.text];
    
    NSString *StoreID=[NSString stringWithFormat:@"%@",customerIdBtn.titleLabel.text];
     NSString *employeeID=[NSString stringWithFormat:@"%@",empIdBtn.titleLabel.text];

    NSString * loginStr;
    NSString * departmentSql;
    //Detailed Daily reports
   
if ([paymentsReports isEqualToString:@"Detailed Daily Reports"]){
            invoiceTableView.hidden=YES;
            displayTableView.hidden=YES;
            
            NSString * flashPaymentSql,*FlashtotalSql;;
            totalTaxArray=[[NSMutableArray alloc]init];
            avgCostArray=[[NSMutableArray alloc]init];
            paymentTypeArray=[[NSMutableArray alloc]init];
            ReportDepartmentsArray=[[NSMutableArray alloc]init];
            
            [self PaymentTypeReportMethod];
            
            if ([fromTFUp.text length]>0 && [toTFUp.text length]>0){
                flashPaymentSql = [NSString stringWithFormat:@"select item_id, discount,total_tax,item_name,item_desscription,price_you_charge,avg_cost,item_quantity,invoice_id,unique_id,created_timestamp,payment_type,in_department,in_vendor,store_id,status,employee,customer from invoice_items_table WHERE status='%@' and created_timestamp BETWEEN '%@ %@' AND '%@ %@'",orderStatus,fromTFUp.text,fromTFDown.text,toTFUp.text,toTFDown.text];
                
                FlashtotalSql = [NSString stringWithFormat:@"select invoice_id from invoice_total_table WHERE status='%@' and created_timestamp BETWEEN '%@ %@' AND '%@ %@'",orderStatus,fromTFUp.text,fromTFDown.text,toTFUp.text,toTFDown.text];
        
            }else{
                flashPaymentSql = [NSString stringWithFormat:@"select item_id, discount,total_tax,item_name,item_desscription,price_you_charge,avg_cost,item_quantity,invoice_id,unique_id,created_timestamp,payment_type,in_department,in_vendor,store_id,status,employee,customer from invoice_items_table WHERE status='%@'",orderStatus];
                
                FlashtotalSql = [NSString stringWithFormat:@"select invoice_id from invoice_total_table WHERE status='%@'",orderStatus];
            }
    
        NSMutableArray *flashInvoiceArray=[[NSMutableArray alloc]init];
         NSMutableArray *flashInvtotalArray=[[NSMutableArray alloc]init];
    
       [[DataBaseManager dataBaseManager]execute:flashPaymentSql resultsArray:flashInvoiceArray];
    
        [[DataBaseManager dataBaseManager]execute:FlashtotalSql resultsArray:flashInvtotalArray];
            
            
    
    @autoreleasepool {
        for (NSDictionary *myDict in flashInvoiceArray)
        {
            NSString * totalTaxStr= [myDict objectForKey:@"total_tax"];
            NSString * avgCostStr= [myDict objectForKey:@"price_you_charge"];
            NSString * Department= [myDict objectForKey:@"in_department"];
            
            //[ReportsItemsArray addObject:[myDict objectForKey:@"item_id"]];
            
            [totalTaxArray addObject:totalTaxStr];
            [avgCostArray addObject:avgCostStr];
            NSUInteger objIdx = [ReportDepartmentsArray containsObject:Department];
            
            if(objIdx == 0)
            {
                [ReportDepartmentsArray addObject:Department];
            }
        }
        for (NSDictionary *myDict in flashInvtotalArray)
        {
            NSString * paymentTypeStr = [myDict objectForKey:@"invoice_id"];
            [paymentTypeArray addObject:paymentTypeStr];
            // // //NSLog(@"the payment values are %@",paymentTypeArray);
        }
    }
            int count=0;
            double SubtotalValue;
            NSString *NetSalesstr;
            
            for (int i=0; i<[avgCostArray count]; i++)
            {
                NSString *price=[avgCostArray objectAtIndex:i];
                price = [price stringByReplacingOccurrencesOfString:@"$ " withString:@""];
                double pricevalue=[price doubleValue];
                
                count=count+1;
                if (count>1){
                    SubtotalValue=SubtotalValue+pricevalue;
                    
                }else{
                    SubtotalValue=pricevalue;
                    
                }
                // //NSLog(@"%f",SubtotalValue);
                NetSalesstr = [NSString stringWithFormat:@"%@%.02f", @"$ ",SubtotalValue];
            }
            int taxcount=0;
            double taxtotalValue;
            NSString *taxesstr;
            
            int nettaxCount=0;
            double taxnetvalue;
            NSString *NetSalestaxedstr;
            
            int netNontaxcout=0;
            double Nontaxnetvalue;
            NSString *NetSalesNontaxedstr=@"$ 0.00";
            
            for (int i=0; i<[totalTaxArray count]; i++)
            {
                
                NSString *price=[totalTaxArray objectAtIndex:i];
                NSString *pricestr=[avgCostArray objectAtIndex:i];
                price = [price stringByReplacingOccurrencesOfString:@"$ " withString:@""];
                double pricevalue=(([price doubleValue]*[pricestr doubleValue])/100);
                taxcount=taxcount+1;
                if (taxcount>1){
                    taxtotalValue=taxtotalValue+pricevalue;
                    
                }else{
                    taxtotalValue=pricevalue;
                    
                }
                //// //NSLog(@"%f",taxtotalValue);
                taxesstr = [NSString stringWithFormat:@"%@%.02f", @"$ ",taxtotalValue];
                
                int taxvalue=[price intValue];
                
                if (taxvalue==0){
                    NSString *price=[avgCostArray objectAtIndex:i];
                    
                    price = [price stringByReplacingOccurrencesOfString:@"$ " withString:@""];
                    
                    
                    double pricevalue=[price doubleValue];
                    
                    netNontaxcout=netNontaxcout+1;
                    if (netNontaxcout>1){
                        Nontaxnetvalue=Nontaxnetvalue+pricevalue;
                        
                    }else{
                        Nontaxnetvalue=pricevalue;
                        
                    }
                   // // //NSLog(@"%f",Nontaxnetvalue);
                    NetSalesNontaxedstr = [NSString stringWithFormat:@"%@%.02f", @"$ ",Nontaxnetvalue];
                    
                }else{
                    NSString *price=[avgCostArray objectAtIndex:i];
                    
                    price = [price stringByReplacingOccurrencesOfString:@"$ " withString:@""];
                    
                    
                    double pricevalue=[price doubleValue];
                    
                    nettaxCount=nettaxCount+1;
                    if (nettaxCount>1){
                        taxnetvalue=taxnetvalue+pricevalue;
                        
                    }else{
                        taxnetvalue=pricevalue;
                        
                    }
                    // //NSLog(@"%f",taxnetvalue);
                    NetSalestaxedstr = [NSString stringWithFormat:@"%@%.02f", @"$ ",taxnetvalue];
                }
                
            }

            double GrassSalesValue=SubtotalValue+taxtotalValue;
            NSString *GrassSalesStr=[NSString stringWithFormat:@"%@%.02f",@"$ ",GrassSalesValue];
           // // //NSLog(@"Grass sales Value is %@",GrassSalesStr);
    
           NSMutableString *stringToPrint = [[NSMutableString alloc] initWithString:@""];
            
            [stringToPrint appendFormat:@"<html><head><style type=\"text/css\">body {background-color:none;font-family : Verdana;color:#000000;font-size:28px;} table td {font-family : Verdana;color:#000000;font-size:28px; padding:0px 15px;} .tablehead{ font-size:32px;} </style><body style='background-color:none;'><center><table cellspacing=\"10\" width=';100%%' align='center' border=\"0\"><tr><th align=\"center\" colspan=\"2\">AonePOS</th></tr>"];
            
            [stringToPrint appendFormat:@"<tr><th align=\"center\" colspan=\"2\"><span class=\"tablehead\">Detailed Daily Reports</span></th></tr>"];
            [stringToPrint appendFormat:@"<tr><th align=\"center\" colspan=\"2\"><span class=\"tablehead\">Sales Total </span></th></tr>"];
            
            [stringToPrint appendFormat:@"<tr><td align=\"left\">Net Sales </td><td align=\"right\">%@<td><tr>",NetSalesstr];
            [stringToPrint appendFormat:@"<tr><td align=\"left\">Net Sales_Taxed </td><td align=\"right\">%@<td><tr>",NetSalestaxedstr];
            [stringToPrint appendFormat:@"<tr><td align=\"left\">Net Sales_Non Taxed </td><td align=\"right\">%@<td><tr>",NetSalesNontaxedstr];
            [stringToPrint appendFormat:@"<tr><td align=\"left\">Exempt Sales </td><td align=\"right\">%@<td><tr>",@"$ 0.00"];
            [stringToPrint appendFormat:@"<tr><td align=\"left\">Taxes </td><td align=\"right\">%@<td><tr>",taxesstr];
            [stringToPrint appendFormat:@"<tr><td align=\"left\">Grass Sales </td><td align=\"right\">%@<td><tr>",GrassSalesStr];
            
            [stringToPrint appendFormat:@"<tr><th align=\"center\" colspan=\"2\"><span class=\"tablehead\">Payment Types </span></th></tr>"];
            
            [stringToPrint appendFormat:@"<tr><td align=\"left\">Cash </td><td align=\"right\">%@<td><tr>",CashTotalstr];
            [stringToPrint appendFormat:@"<tr><td align=\"left\">Cheque </td><td align=\"right\">%@<td><tr>",ChqueTotalstr];
            [stringToPrint appendFormat:@"<tr><td align=\"left\">Card </td><td align=\"right\">%@<td><tr>",cardTotalstr];
          
            
    [self DetailedDailyReportMethod:stringToPrint];
    
        }else if ([paymentsReports isEqualToString:@"Flash Reports"]){
        
        invoiceTableView.hidden=YES;
        displayTableView.hidden=YES;
        NSString * flashPaymentSql,*FlashtotalSql;;
        totalTaxArray=[[NSMutableArray alloc]init];
         avgCostArray=[[NSMutableArray alloc]init];
         paymentTypeArray=[[NSMutableArray alloc]init];
        
        [self PaymentTypeReportMethod];
        
            if ([fromTFUp.text length]>0 && [toTFUp.text length]>0){
                flashPaymentSql = [NSString stringWithFormat:@"select item_id, discount,total_tax,item_name,item_desscription,price_you_charge,avg_cost,item_quantity,invoice_id,unique_id,created_timestamp,payment_type,in_department,in_vendor,store_id,status,employee,customer from invoice_items_table WHERE status='%@' and created_timestamp BETWEEN '%@ %@' AND '%@ %@'",orderStatus,fromTFUp.text,fromTFDown.text,toTFUp.text,toTFDown.text];
                
                FlashtotalSql = [NSString stringWithFormat:@"select invoice_id from invoice_total_table WHERE status='%@' and created_timestamp BETWEEN '%@ %@' AND '%@ %@'",orderStatus,fromTFUp.text,fromTFDown.text,toTFUp.text,toTFDown.text];
                
                
            }else{
            flashPaymentSql = [NSString stringWithFormat:@"select item_id, discount,total_tax,item_name,item_desscription,price_you_charge,avg_cost,item_quantity,invoice_id,unique_id,created_timestamp,payment_type,in_department,in_vendor,store_id,status,employee,customer from invoice_items_table WHERE status='%@'",orderStatus];
                
            FlashtotalSql = [NSString stringWithFormat:@"select invoice_id from invoice_total_table WHERE status='%@'",orderStatus];
        }
            
            NSMutableArray *flashInvoiceArray=[[NSMutableArray alloc]init];
            NSMutableArray *flashInvtotalArray=[[NSMutableArray alloc]init];
            
            [[DataBaseManager dataBaseManager]execute:flashPaymentSql resultsArray:flashInvoiceArray];
            
            [[DataBaseManager dataBaseManager]execute:FlashtotalSql resultsArray:flashInvtotalArray];
      
            @autoreleasepool {
                for (NSDictionary *myDict in flashInvoiceArray)
                {
                    NSString * totalTaxStr= [myDict objectForKey:@"total_tax"];
                    NSString * avgCostStr= [myDict objectForKey:@"price_you_charge"];
                    [totalTaxArray addObject:totalTaxStr];
                    [avgCostArray addObject:avgCostStr];
                    
                }
                for (NSDictionary *myDict in flashInvtotalArray)
                {
                    NSString * paymentTypeStr = [myDict objectForKey:@"invoice_id"];
                    [paymentTypeArray addObject:paymentTypeStr];
                    // // //NSLog(@"the payment values are %@",paymentTypeArray);
                }
            }
           
        
        int count=0;
        double SubtotalValue=0;
        NSString *NetSalesstr;
      
        for (int i=0; i<[avgCostArray count]; i++)
        {
            
            NSString *price=[avgCostArray objectAtIndex:i];
            
            price = [price stringByReplacingOccurrencesOfString:@"$ " withString:@""];
            double pricevalue=[price doubleValue];
            
            count=count+1;
            if (count>1){
                SubtotalValue=SubtotalValue+pricevalue;
                
            }else
            {
                SubtotalValue=pricevalue;
                
            }
            //// //NSLog(@"%f",SubtotalValue);
            NetSalesstr = [NSString stringWithFormat:@"%@%.02f", @"$ ",SubtotalValue];
        }
        int taxcount=0;
        double taxtotalValue=0;
        NSString *taxesstr;
        
        int nettaxCount=0;
        double taxnetvalue;
        NSString *NetSalestaxedstr;
        
        int netNontaxcout=0;
        double Nontaxnetvalue;
        NSString *NetSalesNontaxedstr=@"$ 0.00";
        
        for (int i=0; i<[totalTaxArray count]; i++)
        {
            
            NSString *price=[totalTaxArray objectAtIndex:i];
             NSString *pricestr=[avgCostArray objectAtIndex:i];
            price = [price stringByReplacingOccurrencesOfString:@"$ " withString:@""];
             double pricevalue=(([price doubleValue]*[pricestr doubleValue])/100);
           
            
            taxcount=taxcount+1;
            if (taxcount>1){
                taxtotalValue=taxtotalValue+pricevalue;
                
            }else{
                taxtotalValue=pricevalue;
                
            }
            //// //NSLog(@"%f",taxtotalValue);
            taxesstr = [NSString stringWithFormat:@"%@%.02f", @"$ ",taxtotalValue];
            
            int taxvalue=[price intValue];
            
            if (taxvalue==0){
                NSString *price=[avgCostArray objectAtIndex:i];
                
                price = [price stringByReplacingOccurrencesOfString:@"$ " withString:@""];
                
                
                double pricevalue=[price doubleValue];
                
                netNontaxcout=netNontaxcout+1;
                if (netNontaxcout>1){
                    Nontaxnetvalue=Nontaxnetvalue+pricevalue;
                    
                }else{
                    Nontaxnetvalue=pricevalue;
                    
                }
               // // //NSLog(@"%f",Nontaxnetvalue);
                NetSalesNontaxedstr = [NSString stringWithFormat:@"%@%.02f", @"$ ",Nontaxnetvalue];
                
            }else{
                NSString *price=[avgCostArray objectAtIndex:i];
                
                price = [price stringByReplacingOccurrencesOfString:@"$ " withString:@""];
                
                
                double pricevalue=[price doubleValue];
                
                nettaxCount=nettaxCount+1;
                if (nettaxCount>1){
                    taxnetvalue=taxnetvalue+pricevalue;
                    
                }else{
                    taxnetvalue=pricevalue;
                    
                }
               // // //NSLog(@"%f",taxnetvalue);
                NetSalestaxedstr = [NSString stringWithFormat:@"%@%.02f", @"$ ",taxnetvalue];
            }
            
        }
            double GrassSalesValue;
         GrassSalesValue=SubtotalValue + taxtotalValue;
        NSString *GrassSalesStr=[NSString stringWithFormat:@"%@%.02f",@"$ ",GrassSalesValue];
      //  // //NSLog(@"Grass sales Value is %@",GrassSalesStr);
        
        //calculate transactions
        NSString *TransactionsStr=[NSString stringWithFormat:@"%d",[paymentTypeArray count]];
        
       // // //NSLog(@"transactions str %@",TransactionsStr);
        double avgtransactions=GrassSalesValue/[paymentTypeArray count];
        
          NSString *AvgTransactionsStr=[NSString stringWithFormat:@"%.02f",avgtransactions];
       // // //NSLog(@"avg transactions %@",AvgTransactionsStr);
        
        NSMutableString *stringToPrint = [[NSMutableString alloc] initWithString:@""];
        
        [stringToPrint appendFormat:@"<html><head><style type=\"text/css\">body {background-color:none;font-family : Verdana;color:#000000;font-size:28px;} table td {font-family : Verdana;color:#000000;font-size:28px; padding:0px 15px;} .tablehead{ font-size:32px;} </style><body style='background-color:none;'><center><table cellspacing=\"10\" width=';100%%' align='center' border=\"0\"><tr><th align=\"center\" colspan=\"2\">AonePOS</th></tr>"];
        
         [stringToPrint appendFormat:@"<tr><th align=\"center\" colspan=\"2\"><span class=\"tablehead\">Flash Report </span></th></tr>"];
           [stringToPrint appendFormat:@"<tr><th align=\"center\" colspan=\"2\"><span class=\"tablehead\">Sales Total </span></th></tr>"];
        
           [stringToPrint appendFormat:@"<tr><td align=\"left\">Net Sales </td><td align=\"right\">%@<td><tr>",NetSalesstr];
          [stringToPrint appendFormat:@"<tr><td align=\"left\">Net Sales_Taxed </td><td align=\"right\">%@<td><tr>",NetSalestaxedstr];
          [stringToPrint appendFormat:@"<tr><td align=\"left\">Net Sales_Non Taxed </td><td align=\"right\">%@<td><tr>",NetSalesNontaxedstr];
          [stringToPrint appendFormat:@"<tr><td align=\"left\">Exempt Sales </td><td align=\"right\">%@<td><tr>",@"$ 0.00"];
          [stringToPrint appendFormat:@"<tr><td align=\"left\">Taxes </td><td align=\"right\">%@<td><tr>",taxesstr];
          [stringToPrint appendFormat:@"<tr><td align=\"left\">Grass Sales </td><td align=\"right\">%@<td><tr>",GrassSalesStr];
        
         [stringToPrint appendFormat:@"<tr><th align=\"center\" colspan=\"2\"><span class=\"tablehead\">Payment Types </span></th></tr>"];
        
          [stringToPrint appendFormat:@"<tr><td align=\"left\">Cash </td><td align=\"right\">%@<td><tr>",CashTotalstr];
          [stringToPrint appendFormat:@"<tr><td align=\"left\">Cheque </td><td align=\"right\">%@<td><tr>",ChqueTotalstr];
          [stringToPrint appendFormat:@"<tr><td align=\"left\">Card </td><td align=\"right\">%@<td><tr>",cardTotalstr];
         [stringToPrint appendFormat:@"<tr><th align=\"center\" colspan=\"2\"><span class=\"tablehead\">Performance Statistics </span></th></tr>"];
        
        [stringToPrint appendFormat:@"<tr><td align=\"left\">#Transactions </td><td align=\"right\">%@<td><tr>",TransactionsStr];
        [stringToPrint appendFormat:@"<tr><td align=\"left\">Avg Transactions </td><td align=\"right\">%@<td><tr>",AvgTransactionsStr];
        
         [stringToPrint appendFormat:@"</table></center></body></html>"];
    
            [self FlashReportViewMethod:stringToPrint];
 
    }else if ([paymentsReports isEqualToString:@"Payment Type Reports"]){
        
        invoiceTableView.hidden=YES;
        displayTableView.hidden=YES;
        
        [self PaymentTypeReportMethod];

        UIAlertView * paymentAlert = [[UIAlertView alloc]initWithTitle:@"Payment Types" message:PaymentAlertStr delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK", nil];
        
        
        [paymentAlert show];
        

    }else if ([paymentsReports isEqualToString:@"Invoice Total Reports"]){
        
    if([searchField.text length]>1){
        selectSql = [NSString stringWithFormat:@"select item_id, discount,total_tax,item_name,item_desscription,price_you_charge,avg_cost,item_quantity,invoice_id,unique_id,created_timestamp,payment_type,in_department,in_vendor,store_id,status,employee,customer from invoice_items_table WHERE item_id like '%%%@%%' OR item_name like '%%%@%%'",searchField.text,searchField.text];
      
    }else{
        if ([fromTFUp.text length]>0 && [toTFUp.text length]>0){
            if ([StoreID isEqualToString:@"All"] && [Pay isEqualToString:@"All"]){
                selectSql = [NSString stringWithFormat:@"select item_id, discount,total_tax,item_name,item_desscription,price_you_charge,avg_cost,item_quantity,invoice_id,unique_id,created_timestamp,payment_type,in_department,in_vendor,store_id,status,employee,customer from invoice_items_table WHERE created_timestamp BETWEEN '%@ %@' AND '%@ %@' ",fromTFUp.text,fromTFDown.text,toTFUp.text,toTFDown.text];
            }else{
                if (![StoreID isEqualToString:@"All"] && ![Pay isEqualToString:@"All"]){
                    selectSql = [NSString stringWithFormat:@"select * from invoice_items_table WHERE in_department='%@' and payment_type='%@' and created_timestamp BETWEEN '%@ %@' AND '%@ %@'",StoreID,Pay,fromTFUp.text,fromTFDown.text,toTFUp.text,toTFDown.text];
                }else if ([StoreID isEqualToString:@"All"] && ![Pay isEqualToString:@"All"]){
                    
                    selectSql = [NSString stringWithFormat:@"select item_id, discount,total_tax,item_name,item_desscription,price_you_charge,avg_cost,item_quantity,invoice_id,unique_id,created_timestamp,payment_type,in_department,in_vendor,store_id,status,employee,customer from invoice_items_table WHERE payment_type='%@' and created_timestamp BETWEEN '%@ %@' AND '%@ %@' ",StoreID,fromTFUp.text,fromTFDown.text,toTFUp.text,toTFDown.text];
                    
                }else if (![StoreID isEqualToString:@"All"] && [Pay isEqualToString:@"All"]){
                    
                    selectSql = [NSString stringWithFormat:@"select item_id, discount,total_tax,item_name,item_desscription,price_you_charge,avg_cost,item_quantity,invoice_id,unique_id,created_timestamp,payment_type,in_department,in_vendor,store_id,status,employee,customer from invoice_items_table WHERE in_department='%@' and created_timestamp BETWEEN '%@ %@' AND '%@ %@'",StoreID,fromTFUp.text,fromTFDown.text,toTFUp.text,toTFDown.text];
                }
                
            }
            
          }else{
            if ([StoreID isEqualToString:@"All"] && [Pay isEqualToString:@"All"]){
                selectSql = [NSString stringWithFormat:@"select item_id, discount,total_tax,item_name,item_desscription,price_you_charge,avg_cost,item_quantity,invoice_id,unique_id,created_timestamp,payment_type,in_department,in_vendor,store_id,status,employee,customer from invoice_items_table"];
            }else{
                if (![StoreID isEqualToString:@"All"] && ![Pay isEqualToString:@"All"]){
                    selectSql = [NSString stringWithFormat:@"select item_id, discount,total_tax,item_name,item_desscription,price_you_charge,avg_cost,item_quantity,invoice_id,unique_id,created_timestamp,payment_type,in_department,in_vendor,store_id,status,employee,customer from invoice_items_table WHERE store_id='%@' and payment_type='%@' ",StoreID,Pay];
                    
                }else if ([StoreID isEqualToString:@"All"] && ![Pay isEqualToString:@"All"]){
                    selectSql = [NSString stringWithFormat:@"select item_id, discount,total_tax,item_name,item_desscription,price_you_charge,avg_cost,item_quantity,invoice_id,unique_id,created_timestamp,payment_type,in_department,in_vendor,store_id,status,employee,customer from invoice_items_table WHERE payment_type='%@' ",Pay];
                    
                }else if (![StoreID isEqualToString:@"All"] && [Pay isEqualToString:@"All"]){
                   selectSql = [NSString stringWithFormat:@"select item_id, discount,total_tax,item_name,item_desscription,price_you_charge,avg_cost,item_quantity,invoice_id,unique_id,created_timestamp,payment_type,in_department,in_vendor,store_id,status,employee,customer from invoice_items_table WHERE store_id='%@'",StoreID];
                }
            }
        }
        
    }
        NSMutableArray *invoiceitemsArray=[[NSMutableArray alloc]init];
        [[DataBaseManager dataBaseManager]execute:selectSql resultsArray:invoiceitemsArray];
      
        [self GetInvoiceReportDataMethod:invoiceitemsArray];
        
        if ([invoiceitemsArray count] == 0){
            UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"Alert" message:@"No results Available" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:Nil, nil];
            [alert show];
            
        }else{
           
            displayTableView.hidden=YES;
            departmentWiseTableView.hidden=YES;
            
            invoiceTableView.hidden=NO;

            [invoiceTableView reloadData];
          }
        
   }else if ([paymentsReports isEqualToString:@"Employee Shift Reports"]){
            
          
                if ([fromTFUp.text length]>0 && [toTFUp.text length]>0){
                   
                    if ([employeeID isEqualToString:@"All"] ){
                        loginStr = [NSString stringWithFormat:@"select login_employee_name, login_employee_id,login_time,logout_time,diff_minutes,diff_hours,wages,sessioniduniqueval,unique_id,created_timestamp,modified_timestamp from login_logout_table WHERE created_timestamp BETWEEN '%@ %@' AND '%@ %@'",fromTFUp.text,fromTFDown.text,toTFUp.text,toTFDown.text];
                    }else if (![employeeID isEqualToString:@"All"]){
                        loginStr = [NSString stringWithFormat:@"select login_employee_name, login_employee_id,login_time,logout_time,diff_minutes,diff_hours,wages,sessioniduniqueval,unique_id,created_timestamp,modified_timestamp from login_logout_table WHERE created_timestamp BETWEEN '%@ %@' AND '%@ %@' AND login_employee_id='%@'",fromTFUp.text,fromTFDown.text,toTFUp.text,toTFDown.text,employeeID];
                    }
                }else{
                if ([employeeID isEqualToString:@"All"]){
                    loginStr = [NSString stringWithFormat:@"select login_employee_name, login_employee_id,login_time,logout_time,diff_minutes,diff_hours,wages,sessioniduniqueval,unique_id,created_timestamp,modified_timestamp from login_logout_table "];
                }else if (![employeeID isEqualToString:@"All"]){
                    loginStr = [NSString stringWithFormat:@"select login_employee_name, login_employee_id,login_time,logout_time,diff_minutes,diff_hours,wages,sessioniduniqueval,unique_id,created_timestamp,modified_timestamp from login_logout_table WHERE created_timestamp BETWEEN '%@ %@' AND '%@ %@' AND login_employee_id='%@'",fromTFUp.text,fromTFDown.text,toTFUp.text,toTFDown.text,employeeID];
                }else{
                    loginStr = [NSString stringWithFormat:@"select login_employee_name, login_employee_id,login_time,logout_time,diff_minutes,diff_hours,wages,sessioniduniqueval,unique_id,created_timestamp,modified_timestamp from login_logout_table "];
                }
                    
                   
              }
       NSMutableArray *employeeArray=[[NSMutableArray alloc]init];
       [[DataBaseManager dataBaseManager]execute:loginStr resultsArray:employeeArray];
     [self GetemplooyeereportsDataMethod:employeeArray];
       
    if ([employeeArray count] == 0){
        UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"Alert" message:@"No results Available" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:Nil, nil];
        [alert show];

    }else{
        
        
        departmentWiseTableView.hidden=YES;
        displayTableView.hidden=NO;
        invoiceTableView.hidden=YES;

        [displayTableView reloadData];
        }
       
  }else if ([paymentsReports isEqualToString:@"Department Wise reports"]){
        
        if ([fromTFUp.text length]>0 && [toTFUp.text length]>0){
            if ([deptID isEqualToString:@"All"]){
                departmentSql = [NSString stringWithFormat:@"select item_id, discount,total_tax,item_name,item_desscription,price_you_charge,avg_cost,item_quantity,invoice_id,unique_id,created_timestamp,payment_type,in_department,in_vendor,store_id,status,employee,customer from invoice_items_table WHERE created_timestamp BETWEEN '%@ %@' AND '%@ %@' ",fromTFUp.text,fromTFDown.text,toTFUp.text,toTFDown.text];
            }else if (![deptID isEqualToString:@"All"]){
                departmentSql = [NSString stringWithFormat:@"select item_id, discount,total_tax,item_name,item_desscription,price_you_charge,avg_cost,item_quantity,invoice_id,unique_id,created_timestamp,payment_type,in_department,in_vendor,store_id,status,employee,customer from invoice_items_table WHERE created_timestamp BETWEEN '%@ %@' AND '%@ %@' AND in_department='%@' ",fromTFUp.text,fromTFDown.text,toTFUp.text,toTFDown.text,deptID];
            }
    
        }else{
            if (![deptID isEqualToString:@"All"]){
                
                departmentSql = [NSString stringWithFormat:@"select item_id, discount,total_tax,item_name,item_desscription,price_you_charge,avg_cost,item_quantity,invoice_id,unique_id,created_timestamp,payment_type,in_department,in_vendor,store_id,status,employee,customer from invoice_items_table WHERE in_department='%@'",deptID];
                
                
            }else{
                departmentSql = [NSString stringWithFormat:@"select item_id, discount,total_tax,item_name,item_desscription,price_you_charge,avg_cost,item_quantity,invoice_id,unique_id,created_timestamp,payment_type,in_department,in_vendor,store_id,status,employee,customer from invoice_items_table "];
            }
        }
      
      NSMutableArray *invoiceitemsArray=[[NSMutableArray alloc]init];
      [[DataBaseManager dataBaseManager]execute:departmentSql resultsArray:invoiceitemsArray];
      
      [self GetInvoiceReportDataMethod:invoiceitemsArray];
        
        if ([invoiceitemsArray count] == 0)
        {
            UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"Alert" message:@"No results Available" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:Nil, nil];
            [alert show];
            
        }
        else
        {
        
            departmentWiseTableView.hidden=YES;
            displayTableView.hidden=YES;
            invoiceTableView.hidden = NO;
            [invoiceTableView reloadData];
            
        }
    }
    

}
-(void) GetInvoiceReportDataMethod:(NSMutableArray *)invoiceItemsArray
{
    if (!invoiceitem) {
        invoiceitem= [[NSMutableArray alloc]init];
        invoiceDis = [[NSMutableArray alloc]init];
        invoiceTotalTax = [[NSMutableArray alloc]init];
        invItemName = [[NSMutableArray alloc]init];
        invItemDisp = [[NSMutableArray alloc]init];
        invPriceChange = [[NSMutableArray alloc]init];
        invAvgCost = [[NSMutableArray alloc]init];
        invinItemQut = [[NSMutableArray alloc]init];
        invID = [[NSMutableArray alloc]init];
        invUniqueID = [[NSMutableArray alloc]init];
        
        invCreatedTs = [[NSMutableArray alloc]init];
        invPaymentType = [[NSMutableArray alloc]init];
        invInDept = [[NSMutableArray alloc]init];
        invVendor = [[NSMutableArray alloc]init];
        invStoreId = [[NSMutableArray alloc]init];
        invStatus = [[NSMutableArray alloc]init];
    }
  
    
    @autoreleasepool {
        for (NSDictionary *myDict in invoiceItemsArray)
        {
      
            
            NSString *invoiceitemStr=[myDict objectForKey:@"item_id"];
            NSString *invoiceDisStr=[myDict objectForKey:@"discount"];
            
            NSString * invoiceTotalTaxStr= [myDict objectForKey:@"total_tax"];
            NSString * invItemNameStr= [myDict objectForKey:@"item_name"];
            NSString * invItemDispStr= [myDict objectForKey:@"item_desscription"];
            
            NSString * invPriceChangeStr= [myDict objectForKey:@"price_you_charge"];
            NSString * invAvgCostStr = [myDict objectForKey:@"avg_cost"];
            NSString * invinItemQutStr= [myDict objectForKey:@"item_quantity"];
            NSString * invIDStr= [myDict objectForKey:@"invoice_id"];
            NSString * invUniqueIDStr= [myDict objectForKey:@"unique_id"];
            NSString * invCreatedTsStr= [myDict objectForKey:@"created_timestamp"];
            
            NSString * invPaymentTypeStr = [myDict objectForKey:@"payment_type"];
            NSString * invInDeptStr= [myDict objectForKey:@"in_department"];
            NSString * invVendorStr= [myDict objectForKey:@"in_vendor"];
            NSString * invStoreIdStr= [myDict objectForKey:@"store_id"];
            NSString * invStatusStr= [myDict objectForKey:@"status"];
            
            
            double pricevalue=[invoiceTotalTaxStr doubleValue];
            NSString * SubTotalstr = [NSString stringWithFormat:@"%.02f", pricevalue];
            
            [invoiceitem addObject:invoiceitemStr];
            [invoiceDis addObject:invoiceDisStr];
            [invoiceTotalTax addObject:SubTotalstr];
            [invItemName addObject:invItemNameStr];
            [invItemDisp addObject:invItemDispStr];
            
            [invPriceChange addObject:invPriceChangeStr];
            [invAvgCost addObject:invAvgCostStr];
            [invinItemQut addObject:invinItemQutStr];
            [invID addObject:invIDStr];
            [invUniqueID addObject:invUniqueIDStr];
            [invCreatedTs addObject:invCreatedTsStr];
            
            [invPaymentType addObject:invPaymentTypeStr];
            [invInDept addObject:invInDeptStr];
            [invVendor addObject:invVendorStr];
            [invStoreId addObject:invStoreIdStr];
            [invStatus addObject:invStatusStr];
        }
    }
    
 
}
-(void) GetemplooyeereportsDataMethod:(NSMutableArray *)employeesArray
{
    //loginID = [[NSMutableArray alloc]init];
   
        loginEmp = [[NSMutableArray alloc]init];
        loginEmpID = [[NSMutableArray alloc]init];
        empLoginTime = [[NSMutableArray alloc]init];
        empLogoutTime = [[NSMutableArray alloc]init];
        diffMin = [[NSMutableArray alloc]init];
        diffHours = [[NSMutableArray alloc]init];
        wages = [[NSMutableArray alloc]init];
       // sessionId = [[NSMutableArray alloc]init];
       // //uniqueId = [[NSMutableArray alloc]init];
      //  createdTimeStamp = [[NSMutableArray alloc]init];
       // modifiedTimeStamp = [[NSMutableArray alloc]init];
       // serverLocal = [[NSMutableArray alloc]init];
   
   
    @autoreleasepool {
        for (NSDictionary *myDict in employeesArray)
        {
            // NSString *loginIdStr=[myDict objectForKey:@"_id"];
            NSString *loginEmpStr=[myDict objectForKey:@"login_employee_name"];
            NSString *loginEmpIDStr=[myDict objectForKey:@"login_employee_id"];
            NSString * empLoginTimeStr= [myDict objectForKey:@"login_time"];
            NSString * empLOgoutTimeStr= [myDict objectForKey:@"logout_time"];
            NSString * diffMinStr= [myDict objectForKey:@"diff_minute"];
            NSString * diffHoursStr = [myDict objectForKey:@"diff_hours"];
            NSString * wagesStr= [myDict objectForKey:@"wages"];
            NSString * sessionIdStr= [myDict objectForKey:@"sessioniduniqueval"];
           // NSString * uniqueIdStr= [myDict objectForKey:@"unique_id"];
          //  NSString * createdTimeStampStr= [myDict objectForKey:@"created_timestamp"];
           // NSString * modifiedTimeStampStr= [myDict objectForKey:@"modified_timestamp"];
            //NSString * serverLocalStr= [myDict objectForKey:@"server_local"];
            
            [loginEmp addObject:loginEmpStr];
            [loginEmpID addObject:loginEmpIDStr];
            [empLoginTime addObject:empLoginTimeStr];
            [empLogoutTime addObject:empLOgoutTimeStr];
            if ([diffMinStr length]==0)
            {
                [diffMin addObject:@""];
            }else{
                [diffMin addObject:diffMinStr];
            }
            
            if ([diffHoursStr length]==0)
            {
                [diffHours addObject:@""];
            }else{
                [diffHours addObject:diffHoursStr];
            }
            if ([wagesStr length]==0)
            {
                [wages addObject:@""];
            }else{
                [wages addObject:wagesStr];
            }
            if ([sessionIdStr length]==0)
            {
                [sessionId addObject:@""];
            }else{
                [sessionId addObject:sessionIdStr];
            }
            //[diffHours addObject:diffHoursStr];
            //[wages addObject:wagesStr];
           // [sessionId addObject:sessionIdStr];
            //[uniqueId addObject:uniqueIdStr];
            //[createdTimeStamp addObject:createdTimeStampStr];
            //[modifiedTimeStamp addObject:modifiedTimeStampStr];
            //[serverLocal addObject:serverLocalStr];
        
            
        }
    }
    
    if (!TimesArray)
    TimesArray=[[NSMutableArray alloc]init];
    if ([diffHours count]>0)
    {
        for (int i=0; i<[diffHours count]; i++)
        {
            NSString *hours=[diffHours objectAtIndex:i];
            NSString *minits=[diffMin objectAtIndex:i];
            [TimesArray addObject:[NSString stringWithFormat:@"%@:%@",hours,minits]];
            
        }
    }
}
-(void)DetailedDailyReportMethod:(NSMutableString *)printstring
{
    
    NSString * flashPaymentSql;
     NSString * orderStatus= [NSString stringWithFormat:@"%@",orderStatusBtn.titleLabel.text];
  
    for (int i=0; i<[ReportDepartmentsArray count]; i++)
    {
        NSString *department=[ReportDepartmentsArray objectAtIndex:i];
      
        
        totalTaxArray=[[NSMutableArray alloc]init];
        avgCostArray=[[NSMutableArray alloc]init];
        paymentTypeArray=[[NSMutableArray alloc]init];
        if ([fromTFUp.text length]>0 && [toTFUp.text length]>0){
            flashPaymentSql = [NSString stringWithFormat:@"select item_id, discount,total_tax,item_name,item_desscription,price_you_charge,avg_cost,item_quantity,invoice_id,unique_id,created_timestamp,payment_type,in_department,in_vendor,store_id,status,employee,customer from invoice_items_table WHERE status='%@' and created_timestamp BETWEEN '%@ %@' AND '%@ %@' AND in_department='%@'",orderStatus,fromTFUp.text,fromTFDown.text,toTFUp.text,toTFDown.text,department];
        }else{
            flashPaymentSql = [NSString stringWithFormat:@"select item_id, discount,total_tax,item_name,item_desscription,price_you_charge,avg_cost,item_quantity,invoice_id,unique_id,created_timestamp,payment_type,in_department,in_vendor,store_id,status,employee,customer from invoice_items_table WHERE status='%@' AND in_department='%@'",orderStatus,department];
          
        }
      
        NSMutableArray *invoiceitemsArray=[[NSMutableArray alloc]init];
        
        [[DataBaseManager dataBaseManager]execute:flashPaymentSql resultsArray:invoiceitemsArray];
        
     
        @autoreleasepool {
            for (NSDictionary *myDict in invoiceitemsArray)
            {
                NSString * totalTaxStr= [myDict objectForKey:@"total_tax"];
                NSString * avgCostStr= [myDict objectForKey:@"price_you_charge"];
                NSString * Department= [myDict objectForKey:@"item_id"];
                
                [totalTaxArray addObject:totalTaxStr];
                [avgCostArray addObject:avgCostStr];
                [paymentTypeArray addObject:Department];
                
            }
        }
        int count=0;
        double SubtotalValue=0;
        NSString *NetSalesstr;
        
        for (int i=0; i<[avgCostArray count]; i++)
        {
            
            NSString *price=[avgCostArray objectAtIndex:i];
            
            price = [price stringByReplacingOccurrencesOfString:@"$ " withString:@""];
            
            
            double pricevalue=[price doubleValue];
            
            count=count+1;
            if (count>1){
                SubtotalValue=SubtotalValue+pricevalue;
                
            }else{
                SubtotalValue=pricevalue;
                
            }
            // //NSLog(@"%f",SubtotalValue);
            NetSalesstr = [NSString stringWithFormat:@"%@%.02f", @"$ ",SubtotalValue];
        }
        // //NSLog(@"net sale value%@",NetSalesstr);
        
        //net sales calculation with tax based
        int taxcount=0;
        double taxtotalValue=0;
        NSString *taxesstr;
        
        int nettaxCount=0;
        double taxnetvalue;
        NSString *NetSalestaxedstr;
        
        int netNontaxcout=0;
        double Nontaxnetvalue;
        NSString *NetSalesNontaxedstr=@"$ 0.00";
        
        for (int i=0; i<[totalTaxArray count]; i++)
        {
            
            NSString *price=[totalTaxArray objectAtIndex:i];
            NSString *pricestr=[avgCostArray objectAtIndex:i];
            price = [price stringByReplacingOccurrencesOfString:@"$ " withString:@""];
            double pricevalue=(([price doubleValue]*[pricestr doubleValue])/100);
            
            
            taxcount=taxcount+1;
            if (taxcount>1)
            {
                taxtotalValue=taxtotalValue+pricevalue;
                
            }else{
                taxtotalValue=pricevalue;
                
            }
            // //NSLog(@"%f",taxtotalValue);
            taxesstr = [NSString stringWithFormat:@"%@%.02f", @"$ ",taxtotalValue];
            
            int taxvalue=[price intValue];
            
            if (taxvalue==0){
                NSString *price=[avgCostArray objectAtIndex:i];
                
                price = [price stringByReplacingOccurrencesOfString:@"$ " withString:@""];
                
                
                double pricevalue=[price doubleValue];
                
                netNontaxcout=netNontaxcout+1;
                if (netNontaxcout>1){
                    Nontaxnetvalue=Nontaxnetvalue+pricevalue;
                    
                }else{
                    Nontaxnetvalue=pricevalue;
                    
                }
                // //NSLog(@"%f",Nontaxnetvalue);
                NetSalesNontaxedstr = [NSString stringWithFormat:@"%@%.02f", @"$ ",Nontaxnetvalue];
                
            }else{
                NSString *price=[avgCostArray objectAtIndex:i];
                
                price = [price stringByReplacingOccurrencesOfString:@"$ " withString:@""];
                
                
                double pricevalue=[price doubleValue];
                
                nettaxCount=nettaxCount+1;
                if (nettaxCount>1)
                {
                    taxnetvalue=taxnetvalue+pricevalue;
                    
                }else{
                    taxnetvalue=pricevalue;
                    
                }
                // //NSLog(@"%f",taxnetvalue);
                NetSalestaxedstr = [NSString stringWithFormat:@"%@%.02f", @"$ ",taxnetvalue];
            }
            
        }
        double GrassSalesValue=SubtotalValue+taxtotalValue;
        NSString *GrassSalesStr=[NSString stringWithFormat:@"%@%.02f",@"$ ",GrassSalesValue];
        // //NSLog(@"Grass sales Value is %@",GrassSalesStr);
        
        [printstring appendFormat:@"<tr><th align=\"center\" colspan=\"2\"><span class=\"tablehead\">%@</span></th></tr>",department];
        
        [printstring appendFormat:@"<tr><td align=\"left\">Net Sales </td><td align=\"right\">%@<td><tr>",NetSalesstr];
        [printstring appendFormat:@"<tr><td align=\"left\">Net Sales_Taxed </td><td align=\"right\">%@<td><tr>",NetSalestaxedstr];
        [printstring appendFormat:@"<tr><td align=\"left\">Net Sales_Non Taxed </td><td align=\"right\">%@<td><tr>",NetSalesNontaxedstr];
        [printstring appendFormat:@"<tr><td align=\"left\">Exempt Sales </td><td align=\"right\">%@<td><tr>",@"$ 0.00"];
        [printstring appendFormat:@"<tr><td align=\"left\">Taxes </td><td align=\"right\">%@<td><tr>",taxesstr];
        [printstring appendFormat:@"<tr><td align=\"left\">Grass Sales </td><td align=\"right\">%@<td><tr>",GrassSalesStr];
        
        [printstring appendFormat:@"<tr><td align=\"left\">Items Count </td><td align=\"right\">%d<td><tr>",[paymentTypeArray count]];
    }
    
    [printstring appendFormat:@"</table></center></body></html>"];
    
    
    [self FlashReportViewMethod:printstring];
    
    
    [totalTaxArray removeAllObjects];
    [avgCostArray removeAllObjects];
    [paymentTypeArray removeAllObjects];
    totalTaxArray=nil,avgCostArray=nil,paymentTypeArray=nil;
}
-(void)FlashReportViewMethod:(NSMutableString *)stringtoPrint
{
    if (!FlashpopupView)
    FlashpopupView = [[UIView alloc]init];
    if (isLandScope){
        FlashpopupView .frame= CGRectMake(0, 0, 1024, 768);
    }else{
        FlashpopupView .frame=CGRectMake(0, 0, 768, 1024);
    }
    [FlashpopupView setBackgroundColor:[UIColor colorWithRed:10.0f/255.0f green:10.0f/255.0f blue:10.0f/255.0f alpha:0.7f/1.0f]];
    [self.view addSubview:FlashpopupView];
    
    if (!FlashReportView)
    FlashReportView=[[UIView alloc]init];
    if (isLandScope){
        FlashReportView.frame=CGRectMake(100, 50, FlashpopupView.frame.size.width-200, FlashpopupView.frame.size.height-100);
    }else{
         FlashReportView.frame=CGRectMake(50, 100, FlashpopupView.frame.size.width-100, FlashpopupView.frame.size.height-200);
    }
    [FlashReportView setBackgroundColor:[UIColor colorWithRed:0.0f green:74.0f/255.0f blue:132.0f/255.0f alpha:1.0f]];
    [FlashReportView.layer setBorderWidth:2.0];
    [FlashReportView.layer setBorderColor:[[UIColor whiteColor] CGColor]];
    //AddvendorsView.layer.cornerRadius=8;
    [FlashpopupView addSubview:FlashReportView];
    
    
    @autoreleasepool {
    FlashReportWebView = [[UIWebView alloc] init];
    if (isLandScope)
    {
        FlashReportWebView.frame=CGRectMake(20, 20, FlashReportView.frame.size.width-40, FlashReportView.frame.size.height-100);
    }else{
        FlashReportWebView.frame=CGRectMake(20,25, FlashReportView.frame.size.width-40, FlashReportView.frame.size.height-100);
    }
    //loading HTMl Strin
    [FlashReportWebView loadHTMLString:stringtoPrint baseURL:nil];
    //webView1.hidden=YES;
    [FlashReportWebView setDelegate:nil];
    [FlashReportWebView sizeToFit];
    //add to main view
    [FlashReportView addSubview:FlashReportWebView];
    }
    
    CGFloat flashw=FlashReportView.frame.size.width/2;
    @autoreleasepool {
        PrintFlashBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
        PrintFlashBtn.frame=CGRectMake(flashw-flashw/2+80, FlashReportView.frame.size.height-50, 80,40);
        [PrintFlashBtn addTarget:self action:@selector(PrintFlashReport) forControlEvents:UIControlEventTouchUpInside];
        
        //[SaveTaxButton setTitle:@"Save" forState:UIControlStateNormal];
        [PrintFlashBtn setTitle:@"Print" forState:UIControlStateNormal];
        [PrintFlashBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [PrintFlashBtn setBackgroundImage:[UIImage imageNamed:@"greenbutton2.png"] forState:UIControlStateNormal];
        [FlashReportView addSubview:PrintFlashBtn];
        
        CancelFlashBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
        CancelFlashBtn.frame=CGRectMake(flashw-flashw/2+220, FlashReportView.frame.size.height-50, 80, 40);
        [CancelFlashBtn addTarget:self action:@selector(CancelFlashReport) forControlEvents:UIControlEventTouchUpInside];
        [CancelFlashBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [CancelFlashBtn setTitle:@"Cancel" forState:UIControlStateNormal];
        [CancelFlashBtn setBackgroundImage:[UIImage imageNamed:@"greenbutton2.png"] forState:UIControlStateNormal];
        // [CancelTaxButton setTitle:@"Cancel" forState:UIControlStateNormal];
        [FlashReportView addSubview:CancelFlashBtn];

    
    }
    flashPrintString=[[NSMutableString alloc]init];
    //[self PrintFlashReport:&stringtoPrint];
    flashPrintString=stringtoPrint;
    stringtoPrint=nil;
    
}
-(void)PrintFlashReport
{
    //[self printImageMethod:imagefromstring];
    [FlashReportWebView loadRequest:nil];
    [FlashReportWebView removeFromSuperview];
    FlashReportWebView=nil;
    
    //[FlashReportWebView removeFromSuperview];
    [FlashpopupView removeFromSuperview];
    [FlashpopupView removeFromSuperview];
    
    [self printImageMethod:flashPrintString];
    
    flashPrintString=nil;
}
-(UIImage *) imageFromWebView:(UIWebView *)view
{
    // tempframe to reset view size after image was created
    CGRect tmpFrame         = view.frame;
    
    // set new Frame
    CGRect aFrame               = view.frame;
    aFrame.size.height  = [view sizeThatFits:[[UIScreen mainScreen] bounds].size].height;
    view.frame              = aFrame;
    
    // do image magic
    UIGraphicsBeginImageContext([view sizeThatFits:[[UIScreen mainScreen] bounds].size]);
    
    CGContextRef resizedContext = UIGraphicsGetCurrentContext();
    [view.layer renderInContext:resizedContext];
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    
    UIGraphicsEndImageContext();
    
    // reset Frame of view to origin
    view.frame = tmpFrame;
    return image;
}
-(void)CancelFlashReport
{
    
    [FlashReportWebView loadRequest:nil];
    [FlashReportWebView removeFromSuperview];
    FlashReportWebView=nil;
    
    [FlashReportWebView removeFromSuperview];
     [FlashpopupView removeFromSuperview];
    
}
-(void)PaymentTypeReportMethod
{
    PaymentAlertStr=[[NSMutableString alloc]init];
     NSString *Pay=[NSString stringWithFormat:@"%@",paymentButton.titleLabel.text];
    paymentTypeArray = [[NSMutableArray alloc]init];
    
    NSString *paymentType;
    CashTotalstr=@"$ 0.00";
     ChqueTotalstr=@"$ 0.00";
     cardTotalstr=@"$ 0.00";
    
    if ([Pay isEqualToString:@"All"]){
        if ([fromTFUp.text length]>0 && [toTFUp.text length]>0){
            paymentType =[NSString stringWithFormat:@"SELECT invoice_total_table.invoice_id,  invoice_total_table.payment_type, total_amt,  invoice_total_table.created_timestamp FROM invoice_total_table WHERE  invoice_total_table.payment_type = 'Cash' AND invoice_total_table.created_timestamp BETWEEN '%@ %@' AND '%@ %@' UNION SELECT  invoice_total_table.invoice_id, invoice_total_table.payment_type, amount,  invoice_total_table.created_timestamp FROM  invoice_total_table, split_invoice_table  WHERE invoice_total_table.invoice_id = split_invoice_table.invoice_id AND  invoice_total_table.payment_type= 'multiple'  AND split_invoice_table.payment_type='Cash'",fromTFUp.text,fromTFDown.text,toTFUp.text,toTFDown.text];
            
        }else{
            
            paymentType =[NSString stringWithFormat:@"SELECT invoice_total_table.invoice_id,  invoice_total_table.payment_type, total_amt,  invoice_total_table.created_timestamp FROM invoice_total_table WHERE  invoice_total_table.payment_type = 'Cash'  UNION SELECT  invoice_total_table.invoice_id, invoice_total_table.payment_type, amount,  invoice_total_table.created_timestamp FROM  invoice_total_table, split_invoice_table  WHERE invoice_total_table.invoice_id = split_invoice_table.invoice_id AND  invoice_total_table.payment_type= 'multiple'  AND split_invoice_table.payment_type='Cash'"];
            
        }
        
        NSMutableArray *invoiceArray=[[NSMutableArray alloc]init];
        
        [[DataBaseManager dataBaseManager]execute:paymentType resultsArray:invoiceArray];
        
        //paymentMulti = @"multiple";
        
       
        for (NSDictionary *myDict in invoiceArray)
        {
            NSString *paymentTypeStr= [myDict objectForKey:@"total_amt"];
            
            [paymentTypeArray addObject:paymentTypeStr];
            
           // // //NSLog(@" the values are %@", paymentTypeArray);
        }
        int count=0;
        double SubtotalValue;
       
        for (int i=0; i<[paymentTypeArray count]; i++)
        {
            
            NSString *price=[paymentTypeArray objectAtIndex:i];
            price = [price stringByReplacingOccurrencesOfString:@"$ " withString:@""];
            double pricevalue=[price doubleValue];
            
            count=count+1;
            if (count>1){
                SubtotalValue=SubtotalValue+pricevalue;
                
            }else
            {
                SubtotalValue=pricevalue;
                
            }
            //// //NSLog(@"%f",SubtotalValue);
            CashTotalstr = [NSString stringWithFormat:@"%@%.02f", @"$ ",SubtotalValue];
        }
        //// //NSLog(@"cash value is %@",CashTotalstr);
        if ([CashTotalstr length]>0){
            [PaymentAlertStr appendFormat:@"\nCash      %@\n",CashTotalstr];
        }
        
        //cheque
        
        paymentTypeArray=[[NSMutableArray alloc]init];
        
        if ([fromTFUp.text length]>0 && [toTFUp.text length]>0){
            paymentType =[NSString stringWithFormat:@"SELECT invoice_total_table.invoice_id,  invoice_total_table.payment_type, total_amt,  invoice_total_table.created_timestamp FROM invoice_total_table WHERE  invoice_total_table.payment_type = 'Cheque' AND invoice_total_table.created_timestamp BETWEEN '%@ %@' AND '%@ %@' UNION SELECT  invoice_total_table.invoice_id, invoice_total_table.payment_type, amount,  invoice_total_table.created_timestamp FROM  invoice_total_table, split_invoice_table  WHERE invoice_total_table.invoice_id = split_invoice_table.invoice_id AND  invoice_total_table.payment_type= 'multiple'  AND split_invoice_table.payment_type='Cheque'",fromTFUp.text,fromTFDown.text,toTFUp.text,toTFDown.text];
            
        }else{
            
            paymentType =[NSString stringWithFormat:@"SELECT invoice_total_table.invoice_id,  invoice_total_table.payment_type, total_amt,  invoice_total_table.created_timestamp FROM invoice_total_table WHERE  invoice_total_table.payment_type = 'Cheque'  UNION SELECT  invoice_total_table.invoice_id, invoice_total_table.payment_type, amount,  invoice_total_table.created_timestamp FROM  invoice_total_table, split_invoice_table  WHERE invoice_total_table.invoice_id = split_invoice_table.invoice_id AND  invoice_total_table.payment_type='multiple'  AND split_invoice_table.payment_type='Cheque'"];
            
        }
        
       
        NSMutableArray *invoiceArray2=[[NSMutableArray alloc]init];
        
        [[DataBaseManager dataBaseManager]execute:paymentType resultsArray:invoiceArray2];
        
       // paymentMulti = @"multiple";
  
        for (NSDictionary *myDict in invoiceArray2)
        {
            NSString * paymentTypeStr= [myDict objectForKey:@"total_amt"];
            
            [paymentTypeArray addObject:paymentTypeStr];
            
            //// //NSLog(@" the values are %@", paymentTypeArray);
        }
        int Chequecount=0;
        double chequeSubtotalValue;
      
        for (int i=0; i<[paymentTypeArray count]; i++)
        {
            
            NSString *price=[paymentTypeArray objectAtIndex:i];
            price = [price stringByReplacingOccurrencesOfString:@"$ " withString:@""];
            double pricevalue=[price doubleValue];
            
            Chequecount=Chequecount+1;
            if (Chequecount>1){
                chequeSubtotalValue=chequeSubtotalValue+pricevalue;
                
            }else{
                chequeSubtotalValue=pricevalue;
                
            }
            // //NSLog(@"%f",SubtotalValue);
            ChqueTotalstr = [NSString stringWithFormat:@"%@%.02f", @"$ ",chequeSubtotalValue];
        }
        // //NSLog(@"cash value is %@",ChqueTotalstr);
        if ([ChqueTotalstr length]>0)
        {
            [PaymentAlertStr appendFormat:@"Cheque     %@\n",ChqueTotalstr];
        }
        
        //card
        paymentTypeArray=[[NSMutableArray alloc]init];
        if ([fromTFUp.text length]>0 && [toTFUp.text length]>0){
            
            paymentType =[NSString stringWithFormat:@"SELECT invoice_total_table.invoice_id,  invoice_total_table.payment_type, total_amt,  invoice_total_table.created_timestamp FROM invoice_total_table WHERE  invoice_total_table.payment_type = 'Card' AND invoice_total_table.created_timestamp BETWEEN '%@ %@' AND '%@ %@' UNION SELECT  invoice_total_table.invoice_id, invoice_total_table.payment_type, amount,  invoice_total_table.created_timestamp FROM  invoice_total_table, split_invoice_table  WHERE invoice_total_table.invoice_id = split_invoice_table.invoice_id AND  invoice_total_table.payment_type= 'multiple'  AND split_invoice_table.payment_type='Card'",fromTFUp.text,fromTFDown.text,toTFUp.text,toTFDown.text];
        }else{
            paymentType =[NSString stringWithFormat:@"SELECT invoice_total_table.invoice_id,  invoice_total_table.payment_type, total_amt,  invoice_total_table.created_timestamp FROM invoice_total_table WHERE  invoice_total_table.payment_type = 'Card'  UNION SELECT  invoice_total_table.invoice_id, invoice_total_table.payment_type, amount,  invoice_total_table.created_timestamp FROM  invoice_total_table, split_invoice_table  WHERE invoice_total_table.invoice_id = split_invoice_table.invoice_id AND  invoice_total_table.payment_type= 'multiple'  AND split_invoice_table.payment_type='Card'"];
        }
        
        NSMutableArray *invoiceArray3=[[NSMutableArray alloc]init];
        
        [[DataBaseManager dataBaseManager]execute:paymentType resultsArray:invoiceArray3];
        
       // paymentMulti = @"multiple";
  
        for (NSDictionary *myDict in invoiceArray3)
        {
            NSString * paymentTypeStr= [myDict objectForKey:@"total_amt"];
            
            [paymentTypeArray addObject:paymentTypeStr];
            
            //// //NSLog(@" the values are %@", paymentTypeArray);
        }
        int cardcount=0;
        double cardSubtotalValue;
      
        for (int i=0; i<[paymentTypeArray count]; i++)
        {
            
            NSString *price=[paymentTypeArray objectAtIndex:i];
            price = [price stringByReplacingOccurrencesOfString:@"$ " withString:@""];
            double pricevalue=[price doubleValue];
            
            cardcount=cardcount+1;
            if (cardcount>1){
                cardSubtotalValue=cardSubtotalValue+pricevalue;
                
            }else
            {
                cardSubtotalValue=pricevalue;
                
            }
            //// //NSLog(@"%f",cardSubtotalValue);
            cardTotalstr = [NSString stringWithFormat:@"%@%.02f", @"$ ",cardSubtotalValue];
        }
        //// //NSLog(@"cash value is %@",ChqueTotalstr);
        if ([cardTotalstr length]>0)
        {
            [PaymentAlertStr appendFormat:@"Card      %@\n",cardTotalstr];
        }
        
        //// //NSLog(@"payment type str %@",PaymentAlertStr);
        
        
    }else if ([Pay isEqualToString:@"Cash"]){
        if ([fromTFUp.text length]>0 && [toTFUp.text length]>0){
            paymentType =[NSString stringWithFormat:@"SELECT invoice_total_table.invoice_id,  invoice_total_table.payment_type, total_amt,  invoice_total_table.created_timestamp FROM invoice_total_table WHERE  invoice_total_table.payment_type = 'Cash' AND invoice_total_table.created_timestamp BETWEEN '%@ %@' AND '%@ %@' UNION SELECT  invoice_total_table.invoice_id, invoice_total_table.payment_type, amount,  invoice_total_table.created_timestamp FROM  invoice_total_table, split_invoice_table  WHERE invoice_total_table.invoice_id = split_invoice_table.invoice_id AND  invoice_total_table.payment_type= 'multiple'  AND split_invoice_table.payment_type='Cash'",fromTFUp.text,fromTFDown.text,toTFUp.text,toTFDown.text];
            
        }else{
            
            paymentType =[NSString stringWithFormat:@"SELECT invoice_total_table.invoice_id,  invoice_total_table.payment_type, total_amt,  invoice_total_table.created_timestamp FROM invoice_total_table WHERE  invoice_total_table.payment_type = 'Cash'  UNION SELECT  invoice_total_table.invoice_id, invoice_total_table.payment_type, amount,  invoice_total_table.created_timestamp FROM  invoice_total_table, split_invoice_table  WHERE invoice_total_table.invoice_id = split_invoice_table.invoice_id AND  invoice_total_table.payment_type= 'multiple'  AND split_invoice_table.payment_type='Cash'"];
            
        }
        
       // // //NSLog(@"%@",paymentType);
        NSMutableArray *invoiceArray4=[[NSMutableArray alloc]init];
        
        [[DataBaseManager dataBaseManager]execute:paymentType resultsArray:invoiceArray4];
        
       // paymentMulti = @"multiple";
        
    
        for (NSDictionary *myDict in invoiceArray4)
        {
            NSString * paymentTypeStr= [myDict objectForKey:@"total_amt"];
            // //NSLog(@"pay amount %@",paymentTypeStr);
            
            [paymentTypeArray addObject:paymentTypeStr];
            
           // // //NSLog(@" the values are %@", paymentTypeArray);
        }
        int count=0;
        double SubtotalValue;
     
        for (int i=0; i<[paymentTypeArray count]; i++)
        {
            
            NSString *price=[paymentTypeArray objectAtIndex:i];
            price = [price stringByReplacingOccurrencesOfString:@"$ " withString:@""];
            double pricevalue=[price doubleValue];
            
            count=count+1;
            if (count>1)
            {
                SubtotalValue=SubtotalValue+pricevalue;
                
            }
            else
            {
                SubtotalValue=pricevalue;
                
            }
            ////// //NSLog(@"%f",SubtotalValue);
            CashTotalstr = [NSString stringWithFormat:@"%@%.02f", @"$ ",SubtotalValue];
        }
        //// //NSLog(@"cash value is %@",CashTotalstr);
        if ([CashTotalstr length]>0)
        {
            [PaymentAlertStr appendFormat:@"\nCash      %@\n\n",CashTotalstr];
        }
        
        
    }else if ([Pay isEqualToString:@"Check"]){
        if ([fromTFUp.text length]>0 && [toTFUp.text length]>0){
            paymentType =[NSString stringWithFormat:@"SELECT invoice_total_table.invoice_id,  invoice_total_table.payment_type, total_amt,  invoice_total_table.created_timestamp FROM invoice_total_table WHERE  invoice_total_table.payment_type = 'Cheque' AND invoice_total_table.created_timestamp BETWEEN '%@ %@' AND '%@ %@' UNION SELECT  invoice_total_table.invoice_id, invoice_total_table.payment_type, amount,  invoice_total_table.created_timestamp FROM  invoice_total_table, split_invoice_table  WHERE invoice_total_table.invoice_id = split_invoice_table.invoice_id AND  invoice_total_table.payment_type= 'multiple'  AND split_invoice_table.payment_type='Cheque'",fromTFUp.text,fromTFDown.text,toTFUp.text,toTFDown.text];
            
        }else{
            
            paymentType =[NSString stringWithFormat:@"SELECT invoice_total_table.invoice_id,  invoice_total_table.payment_type, total_amt,  invoice_total_table.created_timestamp FROM invoice_total_table WHERE  invoice_total_table.payment_type = 'Cheque'  UNION SELECT  invoice_total_table.invoice_id, invoice_total_table.payment_type, amount,  invoice_total_table.created_timestamp FROM  invoice_total_table, split_invoice_table  WHERE invoice_total_table.invoice_id = split_invoice_table.invoice_id AND  invoice_total_table.payment_type= 'multiple'  AND split_invoice_table.payment_type='Cheque'"];
            
        }
        
        // //NSLog(@"check query %@",paymentType);
        
        NSMutableArray *invoiceArray5=[[NSMutableArray alloc]init];
        
        [[DataBaseManager dataBaseManager]execute:paymentType resultsArray:invoiceArray5];
        
       // paymentMulti = @"multiple";
 
        for (NSDictionary *myDict in invoiceArray5)
        {
            NSString * paymentTypeStr= [myDict objectForKey:@"total_amt"];
            
            [paymentTypeArray addObject:paymentTypeStr];
            
            // //NSLog(@" the values are %@", paymentTypeArray);
        }
        int Chequecount=0;
        double chequeSubtotalValue;
 
        for (int i=0; i<[paymentTypeArray count]; i++)
        {
            
            NSString *price=[paymentTypeArray objectAtIndex:i];
            
            price = [price stringByReplacingOccurrencesOfString:@"$ " withString:@""];
            double pricevalue=[price doubleValue];
            
            Chequecount=Chequecount+1;
            if (Chequecount>1){
                chequeSubtotalValue=chequeSubtotalValue+pricevalue;
                
            }else
            {
                chequeSubtotalValue=pricevalue;
                
            }
            // //NSLog(@"%f",chequeSubtotalValue);
            ChqueTotalstr = [NSString stringWithFormat:@"%@%.02f", @"$ ",chequeSubtotalValue];
        }
     
        if ([ChqueTotalstr length]>0)
        {
            [PaymentAlertStr appendFormat:@"\nCheque     %@\n\n",ChqueTotalstr];
        }
        
    }else if ([Pay isEqualToString:@"Card"]){
        
        if ([fromTFUp.text length]>0 && [toTFUp.text length]>0){
            
            paymentType =[NSString stringWithFormat:@"SELECT invoice_total_table.invoice_id,  invoice_total_table.payment_type, total_amt,  invoice_total_table.created_timestamp FROM invoice_total_table WHERE  invoice_total_table.payment_type = 'Card' AND invoice_total_table.created_timestamp BETWEEN '%@ %@' AND '%@ %@' UNION SELECT  invoice_total_table.invoice_id, invoice_total_table.payment_type, amount,  invoice_total_table.created_timestamp FROM  invoice_total_table, split_invoice_table  WHERE invoice_total_table.invoice_id = split_invoice_table.invoice_id AND  invoice_total_table.payment_type= 'multiple'  AND split_invoice_table.payment_type='Card'",fromTFUp.text,fromTFDown.text,toTFUp.text,toTFDown.text];
        }else{
            paymentType =[NSString stringWithFormat:@"SELECT invoice_total_table.invoice_id,  invoice_total_table.payment_type, total_amt,  invoice_total_table.created_timestamp FROM invoice_total_table WHERE  invoice_total_table.payment_type = 'Card'  UNION SELECT  invoice_total_table.invoice_id, invoice_total_table.payment_type, amount,  invoice_total_table.created_timestamp FROM  invoice_total_table, split_invoice_table  WHERE invoice_total_table.invoice_id = split_invoice_table.invoice_id AND  invoice_total_table.payment_type= 'multiple'  AND split_invoice_table.payment_type='Card'"];
        }
        
        NSMutableArray *invoiceArray5=[[NSMutableArray alloc]init];
        
        [[DataBaseManager dataBaseManager]execute:paymentType resultsArray:invoiceArray5];
        
        //paymentMulti = @"multiple";

        for (NSDictionary *myDict in invoiceArray5)
        {
            NSString * paymentTypeStr= [myDict objectForKey:@"total_amt"];
            
            [paymentTypeArray addObject:paymentTypeStr];
            
            // //NSLog(@" the values are %@", paymentTypeArray);
        }
        int cardcount=0;
        double cardSubtotalValue;
      
        for (int i=0; i<[paymentTypeArray count]; i++)
        {
            
            NSString *price=[paymentTypeArray objectAtIndex:i];
            price = [price stringByReplacingOccurrencesOfString:@"$ " withString:@""];
            double pricevalue=[price doubleValue];
            
            cardcount=cardcount+1;
            if (cardcount>1){
                cardSubtotalValue=cardSubtotalValue+pricevalue;
                
            }else{
                cardSubtotalValue=pricevalue;
                
            }
            // //NSLog(@"%f",cardSubtotalValue);
            cardTotalstr = [NSString stringWithFormat:@"%@%.02f", @"$ ",cardSubtotalValue];
        }
        // //NSLog(@"cash value is %@",cardTotalstr);
        if ([cardTotalstr length]>0)
        {
            [PaymentAlertStr appendFormat:@"\nCard      %@\n\n",cardTotalstr];
        }
        
        // //NSLog(@"payment type str %@",PaymentAlertStr);
        
        
    }

}
-(void)GetPrinterDataMethod
{
    if (!PrinterIpsArray)
    {
    PrinterIpsArray=[[NSMutableArray alloc]init];
    printcharArray = [[NSMutableArray alloc]init];
    FontsArray = [[NSMutableArray alloc]init];
    AlignsArray = [[NSMutableArray alloc]init];
    languagesArray = [[NSMutableArray alloc]init];
    WidthsArray = [[NSMutableArray alloc]init];
    HeightsArray = [[NSMutableArray alloc]init];
    unitsArray = [[NSMutableArray alloc]init];
    boldsArray = [[NSMutableArray alloc]init];
    UnderlinesArray = [[NSMutableArray alloc]init];
    XpossArray = [[NSMutableArray alloc]init];
    
    spacingsArray = [[NSMutableArray alloc]init];
    printernamesArray = [[NSMutableArray alloc]init];
    IpAddsArray = [[NSMutableArray alloc]init];
    DBPrintertypesArray=[[NSMutableArray alloc]init];
    searchPrinterArray=[[NSMutableArray alloc]init];
    }
    
   
     NSString *querySQL5 = [NSString stringWithFormat: @"SELECT headlines, language,unit,spacing,fontsize,align,Wsize,Hsize,bold,underline,Xposition,printname,print_id,ipaddress,created_timestamp,modified_timestamp,unique_id,printer_type,searchprinter FROM printer"];
    NSMutableArray *printersArray=[[NSMutableArray alloc]init];
    [[DataBaseManager dataBaseManager]execute:querySQL5 resultsArray:printersArray];
    @autoreleasepool {
        for (NSDictionary *myDict in printersArray)
        {
            [PrinterIpsArray addObject:[myDict objectForKey:@"print_id"]];
            
            [printcharArray addObject:[myDict objectForKey:@"headlines"]];
            [FontsArray addObject:[myDict objectForKey:@"fontsize"]];
            [AlignsArray addObject:[myDict objectForKey:@"align"]];
            [languagesArray addObject:[myDict objectForKey:@"language"]];
            [WidthsArray addObject:[myDict objectForKey:@"Wsize"]];
            [HeightsArray addObject:[myDict objectForKey:@"Hsize"]];
            [boldsArray addObject:[myDict objectForKey:@"bold"]];
            [UnderlinesArray addObject:[myDict objectForKey:@"underline"]];
            [XpossArray addObject:[myDict objectForKey:@"Xposition"]];
            [unitsArray addObject:[myDict objectForKey:@"unit"]];
            
            [spacingsArray addObject:[myDict objectForKey:@"spacing"]];
            [printernamesArray addObject:[myDict objectForKey:@"printname"]];
            [IpAddsArray addObject:[myDict objectForKey:@"ipaddress"]];
            
            [DBPrintertypesArray addObject:[myDict objectForKey:@"printer_type"]];
            [searchPrinterArray addObject:[myDict objectForKey:@"searchprinter"]];
            
        }
        

    }
    
    if ([PrinterIpsArray count]>0)
    {
        NSUInteger objIdx = [PrinterIpsArray containsObject:@"printer1"];
        // //NSLog(@"%lu",(unsigned long)objIdx);
        if(objIdx == 0)
        {
            PayPrinterName=[printernamesArray objectAtIndex:0];
            
            printChar=[printcharArray objectAtIndex:0];
            
            font=[FontsArray objectAtIndex:0];
            align=[AlignsArray objectAtIndex:0];
            language=[languagesArray objectAtIndex:0];
            Pwidth=[WidthsArray objectAtIndex:0];
            Pheight=[HeightsArray objectAtIndex:0];
            
            Bold=[boldsArray objectAtIndex:0];
            Underline=[UnderlinesArray objectAtIndex:0];
            
            xposition =[XpossArray objectAtIndex:0];
            spacing=[spacingsArray objectAtIndex:0];
            
            Ipadd=[IpAddsArray objectAtIndex:0];
            
            unit=[unitsArray objectAtIndex:0];
            Dbprintertype=[DBPrintertypesArray objectAtIndex:0];
            SearchPrinterStr=[searchPrinterArray objectAtIndex:0];
            
        }else{
            NSInteger indexno=[PrinterIpsArray indexOfObject:@"printer1"];
            
            
            PayPrinterName=[printernamesArray objectAtIndex:indexno];
            
            printChar=[printcharArray objectAtIndex:indexno];
            
            font=[FontsArray objectAtIndex:indexno];
            align=[AlignsArray objectAtIndex:indexno];
            language=[languagesArray objectAtIndex:indexno];
            Pwidth=[WidthsArray objectAtIndex:indexno];
            Pheight=[HeightsArray objectAtIndex:indexno];
            
            Bold=[boldsArray objectAtIndex:indexno];
            Underline=[UnderlinesArray objectAtIndex:indexno];
            
            xposition =[XpossArray objectAtIndex:indexno];
            spacing=[spacingsArray objectAtIndex:indexno];
            
            Ipadd=[IpAddsArray objectAtIndex:indexno];
            
            unit=[unitsArray objectAtIndex:indexno];
            Dbprintertype=[DBPrintertypesArray objectAtIndex:indexno];
            SearchPrinterStr=[searchPrinterArray objectAtIndex:indexno];
            
        }
    }
}
+ (void)CheckStatusWithPortname:(NSString *)portName portSettings:(NSString *)portSettings
{
    SMPort *starPort = nil;
    
    starPort = [SMPort getPort:portName :portSettings :10000];
    if (starPort == nil)
    {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Fail to Open Port"
                                                        message:@""
                                                       delegate:nil
                                              cancelButtonTitle:@"OK"
                                              otherButtonTitles:nil];
        [alert show];
        
        return;
    }
}
/*- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
{
    if (alertView.tag == 100) //Search Printer
    {
        if (buttonIndex == 0) //Cancel
            return;
        
        NSArray *array;
        switch (buttonIndex)
        {
            case 1: //LAN
                array = [SMPort searchPrinter:@"TCP:"];
                break;
            case 2: //Bluetooth
                array = [SMPort searchPrinter:@"BT:"];
                break;
            case 3: //All
                array = [SMPort searchPrinter];
                break;
        }
    }
}*/

-(void)printImageMethod:(NSString *)printstring
{
    UIWebView   *webView1 = [[UIWebView alloc] initWithFrame:CGRectMake(1069, 0, 600, 500)];
    
    [webView1 loadHTMLString:printstring baseURL:nil];
    //webView1.hidden=YES;
    [webView1 setDelegate:self];
    [webView1 sizeToFit];
    //add to main view
    [self.view addSubview:webView1];
    //[self GetPrint:&webView1];
    
    printstring=nil;
    // [webView1 removeFromSuperview],[webView1 loadRequest:nil],webView1=nil;
}
-(void)GetPrint:(UIWebView **)webview
{

    //UIImageView *myimageView=[[UIImageView alloc]initWithFrame:CGRectMake(100, 100, 600, 600)];
    //[myimageView setImage:[generalDataObject   imageFromWebView:webView1]];
   // [self.view addSubview: myimageView];
    [*webview removeFromSuperview];
    
    
    //[PrinterpopupView removeFromSuperview];
    
    if ([Dbprintertype isEqualToString:@"EPSON"]){
        EposPrint *printer_ = [[EposPrint alloc] init];
        
        int result = [printer_ openPrinter:0 DeviceName:Ipadd Enabled:TRUE Interval:1000];
        if(result != EPOS_OC_SUCCESS)
        {
            [ShowMess showExceptionEpos:result method:@"openPrinter"];
            //[printer release];
            return;
        }
        
        
        //create builder
        EposBuilder *builder = [[EposBuilder alloc] initWithPrinterModel:PayPrinterName Lang:EPOS_OC_MODEL_ANK];
        if(builder == nil)
        {
            return ;
        }
        
        UIImage *printImage=[self imageFromWebView:*webview];
        CGFloat width=printImage.size.width;
        
      
        CGFloat height =printImage.size.width;
        
        //result1 = [builder addText:stringToPrint];
        result1 = [builder addImage:printImage X: 0 Y: 0 Width: width Height: height Color: EPOS_OC_PARAM_DEFAULT];
        
        result1 = [builder addCut: EPOS_OC_CUT_FEED];
        if(result1 != EPOS_OC_SUCCESS){
            [ShowMess showExceptionEpos:result1 method:@"addImage"];
            return ;
        }
        
        result1 = [builder addFeedUnit:[[NSString stringWithFormat:@"%@",unit] intValue]];
        if(result1 != EPOS_OC_SUCCESS){
            [ShowMess showExceptionEpos:result1 method:@"addFeedUnit"];
            return ;
            
        }
        
        //send builder data
        unsigned long status = 0;
        unsigned long battery = 0;
        result1 = [printer_ sendData:builder Timeout:10000 Status:&status Battery:&battery];
        [ShowMess showStatus:result1 status:status battery:battery];
        
        
        //remove builder
        [builder clearCommandBuffer];
        printImage=Nil;
        
    }else if ([Dbprintertype isEqualToString:@"STAR"]){
        
        if (blocking == YES)
        {
            return;
        }
        blocking = YES;
    
        
       // CGFloat imagewidth = [self imageFromWebView:webView1].size.width;
        
        //        [PrinterFunctions PrintTextWithPortname:@"TCP:192.168.1.12" portSettings:@"TCP:192.168.1.12" slashedZero:slashedZero underline:underLine invertColor:invertColor emphasized:emphasized upperline:upperline upsideDown:upsideDown heightExpansion:height widthExpansion:width leftMargin:leftMargin alignment:alignment textData:textData textDataSize:[textNSData length]];
        
        NSString *ipaddress=[NSString stringWithFormat:@"%@:%@",SearchPrinterStr,Ipadd];
        // //NSLog(@"ipaddress  %@",ipaddress);
        
        UIImage *printImage=[self imageFromWebView:*webview];
        CGFloat imagewidth=printImage.size.width;
        
       [PrinterFunctions PrintImageWithPortname:ipaddress portSettings:ipaddress imageToPrint:printImage maxWidth:imagewidth compressionEnable:YES withDrawerKick:YES];
        printImage=Nil;
        // free(textData);
        blocking = NO;
        
    }
    [*webview loadRequest:nil];
    *webview=nil;
}


- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
    
     // ReportTypesArray=[[NSMutableArray alloc]initWithObjects:@"Invoice Total Reports",@"Payment Type Reports",@"Depatment Wise reports", @"Employee Shift Reports",@"Flash Reports",@"Detailed Daily Reports",nil];
    
    NSString *reporttype=[NSString stringWithFormat:@"%@",ReporttypeBtn.titleLabel.text];
    
    if ([reporttype isEqualToString:@"Payment Type Reports"]||[reporttype isEqualToString:@"Department Wise reports"]||[reporttype isEqualToString:@"Flash Reports"]||[reporttype isEqualToString:@"Employee Shift Reports"]||[reporttype isEqualToString:@"Detailed Daily Reports"])
    {
        if(textField == searchField)
        {
            [textField resignFirstResponder];
            // Show you custom picker here....
            return NO;
        }
    }
   
    return YES;
}
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
    
    return YES;
}
- (void)webViewDidStartLoad:(UIWebView *)webView
{
   
   
}
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
    

    // //NSLog(@"webViewDidFinishLoad called");
    [self GetPrint:&webView];
    [webView removeFromSuperview];
    [webView loadRequest:nil];
    webView=nil;
   
}
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
{
    
}
- (void) finishedSearching
{
	[searchField resignFirstResponder];
    
	//SearchlistTable.hidden = YES;
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    [self departmentViewremove];
     [self paymenttypeViewremove];
    
    [self reportViewremove];
    
    [self employeeViewremove];
    [self orderViewremove];
     [self customerViewremove];
}
-(void)backButtonTapped1
{
    [backButton3 setBackgroundImage:[UIImage imageNamed:@""] forState:UIControlStateNormal];
    [backButton3 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [backButton2 setBackgroundImage:[UIImage imageNamed:@""] forState:UIControlStateNormal];
    [backButton2 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    UIImage *btnImg = [UIImage imageNamed:@"highlightedtopmenuitem.png"];
    UIImage *btnGreyImg = [btnImg stretchableImageWithLeftCapWidth:0 topCapHeight:1];
    [backButton setBackgroundImage:btnGreyImg forState:UIControlStateNormal];
    [backButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    
    
}
-(void)backButtonTapped2
{
    [backButton setBackgroundImage:[UIImage imageNamed:@""] forState:UIControlStateNormal];
    [backButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [backButton3 setBackgroundImage:[UIImage imageNamed:@""] forState:UIControlStateNormal];
    [backButton3 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    UIImage *btnImg = [UIImage imageNamed:@"highlightedtopmenuitem.png"];
    UIImage *btnGreyImg = [btnImg stretchableImageWithLeftCapWidth:0 topCapHeight:1];
    [backButton2 setBackgroundImage:btnGreyImg forState:UIControlStateNormal];
    [backButton2 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    
    
}
-(void)backButtonTapped3
{
    
    [backButton setBackgroundImage:[UIImage imageNamed:@""] forState:UIControlStateNormal];
    [backButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [backButton2 setBackgroundImage:[UIImage imageNamed:@""] forState:UIControlStateNormal];
    [backButton2 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    UIImage *btnImg = [UIImage imageNamed:@"highlightedtopmenuitem.png"];
    UIImage *btnGreyImg = [btnImg stretchableImageWithLeftCapWidth:0 topCapHeight:1];
    [backButton3 setBackgroundImage:btnGreyImg forState:UIControlStateNormal];
    [backButton3 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    
    
    
}
- (void)longPress:(UILongPressGestureRecognizer*)gesture
{
    if ( gesture.state == UIGestureRecognizerStateEnded )
    {
        // //NSLog(@"Long Press");
    }
}
- (BOOL)shouldAutorotate
{
    // //NSLog(@"called");
    return YES;
    
}
-(void)updateUI
{
    
    if (isLandScope)
    {
        
        CGFloat width,height;
        
        width=1024;
        height=748;
        backgroundcolorview.frame=CGRectMake(0,y,width,height-100);
        
        
        //  sidemenu.frame=CGRectMake(0, 1,170 ,height-150);
        //sidemenu.hidden=YES;
        
        [categorybutton setFrame:CGRectMake(0.0,p,170,40)];
        navBar.frame=CGRectMake(0, 0,width , 50.0);
        
        [logoBtn setFrame:CGRectMake(60,0,250,50)];
        sationLbl.frame=CGRectMake(navBar.frame.size.width-280, 5,100, 40);
        EmpIdlbl.frame=CGRectMake(navBar.frame.size.width-193, 5,150, 40);
        Timelbl.frame=CGRectMake(navBar.frame.size.width-62, 6,80, 40);
        // mainview.frame=CGRectMake(sidemenu.frame.size.width+10,0,width-(sidemenu.frame.size.width+20),height-150);
        mainview.frame=CGRectMake(10,60,width-20,height-200);
        
        //[backgroundcolorview addSubview:mainview];
        [menubutton setFrame:CGRectMake(0,0,50,50)];
        maintoolBar.frame = CGRectMake(0, 0, mainview.frame.size.width, 40);
        
        logoimageview.frame=CGRectMake(50, (backgroundcolorview.frame.size.height)+5+y,(height-(backgroundcolorview.frame.size.height)-30), (height-(backgroundcolorview.frame.size.height)-30));
        
        [helpiconButton setFrame:CGRectMake(width-180,(backgroundcolorview.frame.size.height)+10+y,70,70)];
        
        
        
        [logouticonButton setFrame:CGRectMake(width-100,(backgroundcolorview.frame.size.height)+10+y,70,70)];
        
 //REports View
        
        whiteView.frame=CGRectMake(10,10,mainview.frame .size.width-20,mainview.frame.size.height-20);
      
        blueView.frame=CGRectMake(10, 10, whiteView.frame.size.width-20, whiteView.frame.size.height-20);
        
        displayTableView.frame = CGRectMake(0, 100, blueView.frame.size.width,blueView.frame.size.height-20);
        
        
        whiteView.frame=CGRectMake(10,10,mainview.frame .size.width-20,mainview.frame.size.height-20);
    
        blueView.frame=CGRectMake(10, 10, whiteView.frame.size.width-20, whiteView.frame.size.height-20);
     
        
        CGFloat RWdth=blueView.frame.size.width/4;
        CGFloat Fwdth=RWdth/2;
        fromLabel .frame= CGRectMake(10, 5, Fwdth,30);
        
        fromTFUp .frame= CGRectMake( fromLabel.frame.size.width,5, Fwdth+30,30);

        fromTFDown.frame = CGRectMake( fromLabel.frame.size.width+fromTFUp.frame.size.width+5,5, Fwdth+30,30);
        
        toLabel.frame=CGRectMake(fromLabel.frame.size.width+30+fromTFUp.frame.size.width+140,5, RWdth-50,30);
        toTFUp .frame= CGRectMake(fromLabel.frame.size.width+fromTFUp.frame.size.width+toLabel.frame.size.width+100,5, Fwdth+30,30);
       
        toTFDown .frame= CGRectMake(fromLabel.frame.size.width+fromTFUp.frame.size.width+toLabel.frame.size.width+100+toTFUp.frame.size.width+5,5, Fwdth+30,30);
        
        departLabel .frame=CGRectMake(10, 45, RWdth-20,30);
        
        departmentButton.frame=CGRectMake(departLabel.frame.size.width,45, RWdth+20,30);
 
        paymentLabel .frame= CGRectMake(departLabel.frame.size.width+departmentButton.frame.size.width+10,45, RWdth-20,30);
        
        paymentButton.frame=CGRectMake(departLabel.frame.size.width+departmentButton.frame.size.width+paymentLabel.frame.size.width-20,45, RWdth+20,30);
       
        Reporttypelbl.frame = CGRectMake(10, 85, RWdth-20,30);
      
        ReporttypeBtn.frame=CGRectMake(departLabel.frame.size.width,85, RWdth+20,30);
        
        Searchlbl.frame =CGRectMake(departLabel.frame.size.width+departmentButton.frame.size.width+10,85, RWdth-20,30);
        searchField.frame = CGRectMake(departLabel.frame.size.width+departmentButton.frame.size.width+paymentLabel.frame.size.width-20,85, RWdth+20,30);
        
        SearchlistTable.frame = CGRectMake(departLabel.frame.size.width+departmentButton.frame.size.width+paymentLabel.frame.size.width-20,5, RWdth+20,80);
        
        goButton.frame=CGRectMake(departLabel.frame.size.width+Fwdth,130, 80,30);
        saveButton.frame=CGRectMake(departLabel.frame.size.width+RWdth,130, 80,30);
        
        printerButton.frame=CGRectMake(departLabel.frame.size.width+RWdth+Fwdth,130, 80,30);
        
        displayTableView.frame = CGRectMake(5,170,blueView.frame.size.width-10,blueView.frame.size.height-295);

 //Department view
        departmentPopUp.frame = CGRectMake(0, 0, 1024, 768);
   
        //departmentPopUp = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 768, 1024)];
    
    departmentTV.frame=CGRectMake(100,200 ,departmentPopUp.frame.size.width-200, departmentPopUp.frame.size.height-400);
    
//reporttypes view
       
      ReportTypeView .frame= CGRectMake(0, 0, 1024, 768);
                 // ReportTypeView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 768, 1024)];
        
        ReportTypeTable .frame=CGRectMake(100,200 ,ReportTypeView.frame.size.width-200, ReportTypeView.frame.size.height-400);
        
//Payment view
       
            paymentPopUp .frame= CGRectMake(0, 0, 1024, 768);
       
            //paymentPopUp = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 768, 1024)];
        
        paymentTV.frame = CGRectMake(100,200 ,paymentPopUp.frame.size.width-200, paymentPopUp.frame.size.height-400);
        
//displying reports in tableview
        
         invoiceTableView.frame = CGRectMake(5,290,blueView.frame.size.width-10,blueView.frame.size.height-295);
        
        departmentWiseTableView.frame = CGRectMake(5,290,blueView.frame.size.width-10,blueView.frame.size.height-295);
        
     
        
         subview1.frame=CGRectMake(0, 0,1024, 768);
        
        
        empIdlabel .frame= CGRectMake(10, 125, RWdth-20,30);
      
        empIdBtn.frame=CGRectMake(departLabel.frame.size.width,125, RWdth+20,30);
        
        orderStatusLbl.frame =CGRectMake(10, 165, RWdth-20,30);
     
        orderStatusBtn.frame=CGRectMake(departLabel.frame.size.width,165, RWdth+20,30);
    
        customerIdLabel .frame= CGRectMake(departLabel.frame.size.width+departmentButton.frame.size.width+10,125, RWdth-20,30);
      
      
        customerIdBtn.frame= CGRectMake(departLabel.frame.size.width+departmentButton.frame.size.width+paymentLabel.frame.size.width-20,125, RWdth+20,30);
        
        //Updates in reports of divya coding
        
        
        
        
        SearchlistTable.frame =CGRectMake(departLabel.frame.size.width+departmentButton.frame.size.width+paymentLabel.frame.size.width-20,5, RWdth+20,80);
        
        goButton.frame=CGRectMake(departLabel.frame.size.width+Fwdth,240, 80,30);
      
        saveButton.frame=CGRectMake(departLabel.frame.size.width+RWdth,240, 80,30);
     
        printerButton.frame=CGRectMake(departLabel.frame.size.width+RWdth+Fwdth,240, 80,30);
        
        displayTableView.frame = CGRectMake(5,290,blueView.frame.size.width-10,blueView.frame.size.height-295);
        
        //Divya Coding
        
       
        invoiceTableView.frame = CGRectMake(5,290,blueView.frame.size.width-10,blueView.frame.size.height-295);
       
        departmentWiseTableView.frame = CGRectMake(5,290,blueView.frame.size.width-10,blueView.frame.size.height-295);
        
 //order view
        orderView.frame = CGRectMake(0, 0, 1024, 768);
   
        //orderView.frame = CGRectMake(0, 0, 768, 1024);
    
    orderTableView .frame= CGRectMake(100,200 ,orderView.frame.size.width-200, orderView.frame.size.height-400);
 
//emp view
        
        empIdView .frame= CGRectMake(0, 0, 1024, 768);
  
        //empIdView.frame =CGRectMake(0, 0, 768, 1024);
    
    empIDTableView.frame=CGRectMake(100,200 ,empIdView.frame.size.width-200, empIdView.frame.size.height-400);
        
//customer View
        
        customerView.frame = CGRectMake(0, 0, 1024, 768);
  
      //  customerView.frame = CGRectMake(0, 0, 768, 1024);
    
    customerTableView.frame=CGRectMake(100,200 ,customerView.frame.size.width-200, customerView.frame.size.height-400);
    
        
 //Flash Report View
        
        
        FlashpopupView .frame= CGRectMake(0, 0, 1024, 768);
       // FlashpopupView.frame=CGRectMake(0, 0, 768, 1024);
  
        
        FlashReportView.frame=CGRectMake(100, 50, FlashpopupView.frame.size.width-200, FlashpopupView.frame.size.height-100);
  
       // FlashReportView.frame=CGRectMake(50, 100, FlashpopupView.frame.size.width-100, FlashpopupView.frame.size.height-200);
        
  
        FlashReportWebView.frame=CGRectMake(20, 20, FlashReportView.frame.size.width-40, FlashReportView.frame.size.height-100);
   
       // FlashReportWebView.frame=CGRectMake(20,25, FlashReportView.frame.size.width-40, FlashReportView.frame.size.height-100);
 
    
    CGFloat flashw=FlashReportView.frame.size.width/2;
   
    PrintFlashBtn.frame=CGRectMake(flashw-flashw/2+80, FlashReportView.frame.size.height-50, 80,40);
    CancelFlashBtn.frame=CGRectMake(flashw-flashw/2+220, FlashReportView.frame.size.height-50, 80, 40);
        
        
    }
    else
    {
        CGFloat width,height;
        height=1004;
        width=768;
        // //NSLog(@" %f,%f",width,height);
        
        
        backgroundcolorview.frame=CGRectMake(0,y,width,height-100);
        navBar.frame=CGRectMake(0, 0,width , 50.0);
        [logoBtn setFrame:CGRectMake(60,0,250,50)];
        sationLbl.frame=CGRectMake(navBar.frame.size.width-280, 5,100, 40);
        EmpIdlbl.frame=CGRectMake(navBar.frame.size.width-193, 5,150, 40);
        Timelbl.frame=CGRectMake(navBar.frame.size.width-62, 6,80, 40);
        //sidemenu.frame=CGRectMake(0, 1,170 ,height-150);
        // sidemenu.hidden=YES;
        [categorybutton setFrame:CGRectMake(0.0,p,170,40)];
        mainview.frame=CGRectMake(10,60,width-20,height-200);
        [menubutton setFrame:CGRectMake(0,0,50,50)];
        
        maintoolBar.frame = CGRectMake(0, 0, mainview.frame.size.width, 40);
        //downtoolBar.frame = CGRectMake(0, 0, mainview.frame.size.width, 40);
        
        logoimageview.frame=CGRectMake(50, (backgroundcolorview.frame.size.height)+5+y,(height-(backgroundcolorview.frame.size.height)-30), (height-(backgroundcolorview.frame.size.height)-30));
        
        [helpiconButton setFrame:CGRectMake(width-180,(backgroundcolorview.frame.size.height)+10+y,70,70)];
        
        
        [logouticonButton setFrame:CGRectMake(width-100,(backgroundcolorview.frame.size.height)+10+y,70,70)];
        whiteView.frame=CGRectMake(10,10,mainview.frame .size.width-20,mainview.frame.size.height-20);
        
        blueView.frame=CGRectMake(10, 10, whiteView.frame.size.width-20, whiteView.frame.size.height-20);
        
//REports View
        
        whiteView.frame=CGRectMake(10,10,mainview.frame .size.width-20,mainview.frame.size.height-20);
        
        blueView.frame=CGRectMake(10, 10, whiteView.frame.size.width-20, whiteView.frame.size.height-20);
        
        displayTableView.frame = CGRectMake(0, 100, blueView.frame.size.width,blueView.frame.size.height-20);
        
        
        whiteView.frame=CGRectMake(10,10,mainview.frame .size.width-20,mainview.frame.size.height-20);
        
        blueView.frame=CGRectMake(10, 10, whiteView.frame.size.width-20, whiteView.frame.size.height-20);
        
        
        CGFloat RWdth=blueView.frame.size.width/4;
        CGFloat Fwdth=RWdth/2;
        
        fromLabel .frame= CGRectMake(10, 5, Fwdth,30);
        
        fromTFUp .frame= CGRectMake( fromLabel.frame.size.width,5, Fwdth+30,30);
        
        fromTFDown.frame = CGRectMake( fromLabel.frame.size.width+fromTFUp.frame.size.width+5,5, Fwdth+30,30);
        
        toLabel.frame=CGRectMake(fromLabel.frame.size.width+30+fromTFUp.frame.size.width+140,5, RWdth-50,30);
        toTFUp .frame= CGRectMake(fromLabel.frame.size.width+fromTFUp.frame.size.width+toLabel.frame.size.width+100,5, Fwdth+30,30);
        
        toTFDown .frame= CGRectMake(fromLabel.frame.size.width+fromTFUp.frame.size.width+toLabel.frame.size.width+100+toTFUp.frame.size.width+5,5, Fwdth+30,30);
        
        departLabel .frame=CGRectMake(10, 45, RWdth-20,30);
        
        departmentButton.frame=CGRectMake(departLabel.frame.size.width,45, RWdth+20,30);
        
        paymentLabel .frame= CGRectMake(departLabel.frame.size.width+departmentButton.frame.size.width+10,45, RWdth-20,30);
        
        paymentButton.frame=CGRectMake(departLabel.frame.size.width+departmentButton.frame.size.width+paymentLabel.frame.size.width-20,45, RWdth+20,30);
        
        Reporttypelbl.frame = CGRectMake(10, 85, RWdth-20,30);
        
        ReporttypeBtn.frame=CGRectMake(departLabel.frame.size.width,85, RWdth+20,30);
        
        Searchlbl.frame =CGRectMake(departLabel.frame.size.width+departmentButton.frame.size.width+10,85, RWdth-20,30);
        searchField.frame = CGRectMake(departLabel.frame.size.width+departmentButton.frame.size.width+paymentLabel.frame.size.width-20,85, RWdth+20,30);
        
        SearchlistTable.frame = CGRectMake(departLabel.frame.size.width+departmentButton.frame.size.width+paymentLabel.frame.size.width-20,5, RWdth+20,80);
        
        goButton.frame=CGRectMake(departLabel.frame.size.width+Fwdth,130, 80,30);
        saveButton.frame=CGRectMake(departLabel.frame.size.width+RWdth,130, 80,30);
        
        printerButton.frame=CGRectMake(departLabel.frame.size.width+RWdth+Fwdth,130, 80,30);
        
        displayTableView.frame = CGRectMake(5,170,blueView.frame.size.width-10,blueView.frame.size.height-295);

        
//Department view
       // departmentPopUp = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 1024, 768)];
        
        departmentPopUp.frame = CGRectMake(0, 0, 768, 1024);
        
        departmentTV.frame=CGRectMake(100,200 ,departmentPopUp.frame.size.width-200, departmentPopUp.frame.size.height-400);
    
  
//reporttypes view
        
        //ReportTypeView .frame= CGRectMake(0, 0, 1024, 768);
        ReportTypeView.frame = CGRectMake(0, 0, 768, 1024);
        
        ReportTypeTable .frame=CGRectMake(100,200 ,ReportTypeView.frame.size.width-200, ReportTypeView.frame.size.height-400);
        
        
//Payment view
        
        //paymentPopUp .frame= CGRectMake(0, 0, 1024, 768);
        
       paymentPopUp.frame =CGRectMake(0, 0, 768, 1024);
        
        paymentTV.frame = CGRectMake(100,200 ,paymentPopUp.frame.size.width-200, paymentPopUp.frame.size.height-400);
        
        
//Displying tableview
        
        invoiceTableView.frame = CGRectMake(5,290,blueView.frame.size.width-10,blueView.frame.size.height-295);
        
        departmentWiseTableView.frame = CGRectMake(5,290,blueView.frame.size.width-10,blueView.frame.size.height-295);
        

        
         subview1.frame=CGRectMake(0, 0,768, 1024);
        
        empIdlabel .frame= CGRectMake(10, 125, RWdth-20,30);
        
        empIdBtn.frame=CGRectMake(departLabel.frame.size.width,125, RWdth+20,30);
        
        orderStatusLbl.frame =CGRectMake(10, 165, RWdth-20,30);
        
        orderStatusBtn.frame=CGRectMake(departLabel.frame.size.width,165, RWdth+20,30);
        
        customerIdLabel .frame= CGRectMake(departLabel.frame.size.width+departmentButton.frame.size.width+10,125, RWdth-20,30);
        
        
        customerIdBtn.frame= CGRectMake(departLabel.frame.size.width+departmentButton.frame.size.width+paymentLabel.frame.size.width-20,125, RWdth+20,30);
        
        //Updates in reports of divya coding
        
        
        
        
        SearchlistTable.frame =CGRectMake(departLabel.frame.size.width+departmentButton.frame.size.width+paymentLabel.frame.size.width-20,5, RWdth+20,80);
        
        goButton.frame=CGRectMake(departLabel.frame.size.width+Fwdth,240, 80,30);
        
        saveButton.frame=CGRectMake(departLabel.frame.size.width+RWdth,240, 80,30);
        
        printerButton.frame=CGRectMake(departLabel.frame.size.width+RWdth+Fwdth,240, 80,30);
        
        displayTableView.frame = CGRectMake(5,290,blueView.frame.size.width-10,blueView.frame.size.height-295);
        
        //Divya Coding
        
        
        invoiceTableView.frame = CGRectMake(5,290,blueView.frame.size.width-10,blueView.frame.size.height-295);
        
        departmentWiseTableView.frame = CGRectMake(5,290,blueView.frame.size.width-10,blueView.frame.size.height-295);
        
//order view
        //orderView.frame = CGRectMake(0, 0, 1024, 768);
        
       orderView.frame = CGRectMake(0, 0, 768, 1024);
        
        orderTableView .frame= CGRectMake(100,200 ,orderView.frame.size.width-200, orderView.frame.size.height-400);
        
//emp view
        
        //empIdView .frame= CGRectMake(0, 0, 1024, 768);
        
        empIdView.frame =CGRectMake(0, 0, 768, 1024);
        
        empIDTableView.frame=CGRectMake(100,200 ,empIdView.frame.size.width-200, empIdView.frame.size.height-400);
        
//customer View
        
        //customerView.frame = CGRectMake(0, 0, 1024, 768);
        
        customerView.frame = CGRectMake(0, 0, 768, 1024);
        
        customerTableView.frame=CGRectMake(100,200 ,customerView.frame.size.width-200, customerView.frame.size.height-400);
        
//Flash Report View
        
        
       // FlashpopupView .frame= CGRectMake(0, 0, 1024, 768);
       FlashpopupView.frame=CGRectMake(0, 0, 768, 1024);
        
        
        //FlashReportView.frame=CGRectMake(100, 50, FlashpopupView.frame.size.width-200, FlashpopupView.frame.size.height-100);
        
       FlashReportView.frame=CGRectMake(50, 100, FlashpopupView.frame.size.width-100, FlashpopupView.frame.size.height-200);
        
        
        //FlashReportWebView.frame=CGRectMake(20, 20, FlashReportView.frame.size.width-40, FlashReportView.frame.size.height-100);
        
       FlashReportWebView.frame=CGRectMake(20,25, FlashReportView.frame.size.width-40, FlashReportView.frame.size.height-100);
        
        
        CGFloat flashw=FlashReportView.frame.size.width/2;
        
        PrintFlashBtn.frame=CGRectMake(flashw-flashw/2+80, FlashReportView.frame.size.height-50, 80,40);
        CancelFlashBtn.frame=CGRectMake(flashw-flashw/2+220, FlashReportView.frame.size.height-50, 80, 40);
       
        
    }
    
}

-(void)menuclicked
{
    if (menuslected == false)
    {
        
        // //NSLog(@"called");
        // //NSLog(@"%d",menuslected);
        menuslected=YES;
        logoBtn.hidden=YES;
        
        //[UIView beginAnimations:nil context:NULL];
        //[UIView setAnimationDuration:1.0f];
        sidemenu.transform = CGAffineTransformMakeTranslation(0,0);
        //[SideMenuView setBackgroundColor:[UIColor whiteColor]];
        //sidemenu.hidden=NO;
       // [UIView commitAnimations];
        [backgroundcolorview addSubview:sidemenu];
        
       // [UIView beginAnimations:nil context:NULL];
       // [UIView setAnimationDuration:0.9f];
        menubutton.transform = CGAffineTransformMakeTranslation(180,0);
        
        menubutton.transform = CGAffineTransformRotate( menubutton.transform, - M_PI);
       // [UIView commitAnimations];
        //[UIView beginAnimations:nil context:NULL];
        //[UIView setAnimationDuration:1.0f];
        
        
    }else
    {
        
        menuslected=NO;
        logoBtn.hidden=NO;
        
        //[UIView beginAnimations:nil context:NULL];
        //[UIView setAnimationDuration:1.0f];
        sidemenu.transform = CGAffineTransformMakeTranslation(-250,0);
        
        //[UIView commitAnimations];
        
        
        
        
        //[UIView beginAnimations:nil context:NULL];
        //[UIView setAnimationDuration:1.0f];
        menubutton.transform = CGAffineTransformMakeTranslation(0,0);
        
        
       // [UIView commitAnimations];
       /// [UIView beginAnimations:nil context:NULL];
       // [UIView setAnimationDuration:1.0f];
        
    }
    
}

-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
    
    logoBtn.hidden=NO;
   // [UIView beginAnimations:nil context:NULL];
    //[UIView setAnimationDuration:0.8f];
    mainview.transform = CGAffineTransformMakeTranslation(0,0);
    
    
    //[UIView commitAnimations];
    //[UIView beginAnimations:nil context:NULL];
    //[UIView setAnimationDuration:0.8f];
    sidemenu.transform = CGAffineTransformMakeTranslation(-250,0);
    //[SideMenuView setBackgroundColor:[UIColor whiteColor]];
    
//    [UIView commitAnimations];
//    [UIView commitAnimations];
//    [UIView beginAnimations:nil context:NULL];
//    [UIView setAnimationDuration:0.0f];
    menubutton.transform = CGAffineTransformMakeTranslation(0,0);
    
    
    //[UIView commitAnimations];
    //[UIView beginAnimations:nil context:NULL];
   // [UIView setAnimationDuration:0.0f];
    menuslected=NO;
}

-(void)helpiconclicked
{
    
}
-(void)logoutButtonClicked
{
    [serverSyncClassObject LogoutMethod];
    
    NSString *updateSQL =@"UPDATE miscellaneous SET userType=?,sessionId=?,userID=?";
    NSMutableArray *misUpdatearray=[[NSMutableArray alloc]initWithObjects:@"",@"",@"", nil];
    [[DataBaseManager dataBaseManager] executeRecordsWithQuery:updateSQL withArguments:misUpdatearray];
    [self.navigationController popToRootViewControllerAnimated:YES];
      [generalDataObject  releasevariable];
    [self releaseViews];
}

-(void)categotybuttonclicked:(UIButton *)sender
{
    NSArray *viewS = [self.navigationController viewControllers];
    //NSLog(@"nav views %@",viewS);
    NSInteger selectedrow=sender.tag;
    if(selectedrow == 0){
        Home *homeview=[[Home alloc]initWithNibName:@"Home" bundle:Nil];
        NSString *returnvalue;
        NSInteger selectedview;
        for (int m=0;m<[self.navigationController.viewControllers count] ; m++)
        {
            if([[self.navigationController.viewControllers objectAtIndex:m] isKindOfClass:[Home class]])
            {
                returnvalue=@"yes";
                selectedview=m;
                break;
            }
            
        }
        ////NSLog(@"%d",selectedview);
        if([returnvalue isEqualToString:@"yes"])
        {
            [self.navigationController popToViewController:[viewS objectAtIndex:selectedview] animated:YES];
            [self releaseViews];
        }else{
            
            [self.navigationController pushViewController:homeview animated:NO];
            [self releaseViews];
        }
        
    }else if(selectedrow == 5){
        if ([[generalDataObject  userType] isEqualToString:@"employee"])
        {
            if ([[generalDataObject  settings_permission] isEqualToString:@"yes"])
            {
                [sender setImage:[UIImage imageNamed:@"settingsactive2.png"] forState:UIControlStateNormal];
                NSString *returnvalue;
                NSInteger selectedview;
                Settings  *settingsview=[[Settings alloc]initWithNibName:@"Settings" bundle:Nil];
                for (int m=0;m<[self.navigationController.viewControllers count] ; m++)
                {
                    if([[self.navigationController.viewControllers objectAtIndex:m] isKindOfClass:[Settings class]])
                    {
                        returnvalue=@"yes";
                        selectedview=m;
                        break;
                    }
                    
                }
                if([returnvalue isEqualToString:@"yes"])
                {
                    [self.navigationController popToViewController:[viewS objectAtIndex:selectedview] animated:YES];
                    [self releaseViews];
                }else
                {
                    
                    [self.navigationController pushViewController:settingsview animated:NO];
                    [self releaseViews];
                }
                
            }else{
                
                UIAlertView *authalert=[[UIAlertView alloc]initWithTitle:@"Authentication:" message:@"User not authenticated" delegate:self cancelButtonTitle:@"ok" otherButtonTitles:Nil, nil];
                
                [authalert show];
            }
        }else{
            [sender setImage:[UIImage imageNamed:@"settingsactive2.png"] forState:UIControlStateNormal];
            NSString *returnvalue;
            NSInteger selectedview;
            Settings  *settingsview=[[Settings alloc]initWithNibName:@"Settings" bundle:Nil];
            for (int m=0;m<[self.navigationController.viewControllers count] ; m++)
            {
                if([[self.navigationController.viewControllers objectAtIndex:m] isKindOfClass:[Settings class]])
                {
                    returnvalue=@"yes";
                    selectedview=m;
                    break;
                }
                
            }
            if([returnvalue isEqualToString:@"yes"])
            {
                [self.navigationController popToViewController:[viewS objectAtIndex:selectedview] animated:YES];
                [self releaseViews];
            }else
            {
                [self.navigationController pushViewController:settingsview animated:NO];
                [self releaseViews];
            }
            
            
        }
        
        
    }else if(selectedrow == 8){
        NSString *returnvalue;
        NSInteger selectedview;
        Stores *storesview=[[Stores alloc]initWithNibName:@"Stores" bundle:Nil];
        for (int m=0;m<[self.navigationController.viewControllers count] ; m++)
        {
            if([[self.navigationController.viewControllers objectAtIndex:m] isKindOfClass:[Stores class]])
            {
                returnvalue=@"yes";
                selectedview=m;
                break;
            }
            
        }
        if([returnvalue isEqualToString:@"yes"])
        {
            [self.navigationController popToViewController:[viewS objectAtIndex:selectedview] animated:YES];
            [self releaseViews];
        }else
        {
            
            [self.navigationController pushViewController:storesview animated:NO];
            [self releaseViews];
        }
        
    }else if(selectedrow == 2){
        
        if ([[generalDataObject  userType] isEqualToString:@"employee"])
        {
            if ([[generalDataObject  inventory_permission] isEqualToString:@"yes"])
            {
                NSString *returnvalue;
                NSInteger selectedview;
                Inventory *inventoryview=[[Inventory alloc]initWithNibName:@"Inventory" bundle:Nil];
                for (int m=0;m<[self.navigationController.viewControllers count] ; m++)
                {
                    if([[self.navigationController.viewControllers objectAtIndex:m] isKindOfClass:[Inventory class]])
                    {
                        returnvalue=@"yes";
                        selectedview=m;
                        break;
                    }
                    
                }
                if([returnvalue isEqualToString:@"yes"])
                {
                    [self.navigationController popToViewController:[viewS objectAtIndex:selectedview] animated:YES];
                    [self releaseViews];
                }else
                {
                    
                    [self.navigationController pushViewController:inventoryview animated:NO];
                    [self releaseViews];
                }
                
            }else{
                
                UIAlertView *authalert=[[UIAlertView alloc]initWithTitle:@"Authentication:" message:@"User not authenticated" delegate:self cancelButtonTitle:@"ok" otherButtonTitles:Nil, nil];
                
                [authalert show];
            }
        }
        else
        {
            
            NSString *returnvalue;
            NSInteger selectedview;
            Inventory *inventoryview=[[Inventory alloc]initWithNibName:@"Inventory" bundle:Nil];
            for (int m=0;m<[self.navigationController.viewControllers count] ; m++)
            {
                if([[self.navigationController.viewControllers objectAtIndex:m] isKindOfClass:[Inventory class]])
                {
                    returnvalue=@"yes";
                    selectedview=m;
                    break;
                }
                
            }
            if([returnvalue isEqualToString:@"yes"])
            {
                [self.navigationController popToViewController:[viewS objectAtIndex:selectedview] animated:YES];
                [self releaseViews];
            }else
            {
                
                [self.navigationController pushViewController:inventoryview animated:NO];
                [self releaseViews];
            }
        }
    }else if(selectedrow == 3){
        
        if ([[generalDataObject  userType] isEqualToString:@"employee"])
        {
            if ([[generalDataObject  customer_permission] isEqualToString:@"yes"])
            {
                NSString *returnvalue;
                NSInteger selectedview;
                Customers *customersview=[[Customers alloc]initWithNibName:@"Customers" bundle:Nil];
                for (int m=0;m<[self.navigationController.viewControllers count] ; m++)
                {
                    if([[self.navigationController.viewControllers objectAtIndex:m] isKindOfClass:[Customers class]])
                    {
                        returnvalue=@"yes";
                        selectedview=m;
                        break;
                    }
                    
                }
                if([returnvalue isEqualToString:@"yes"])
                {
                    [self.navigationController popToViewController:[viewS objectAtIndex:selectedview] animated:YES];
                    [self releaseViews];
                }else
                {
                    
                    [self.navigationController pushViewController:customersview animated:NO];
                    [self releaseViews];
                }
                
            }else{
                
                UIAlertView *authalert=[[UIAlertView alloc]initWithTitle:@"Authentication:" message:@"User not authenticated" delegate:self cancelButtonTitle:@"ok" otherButtonTitles:Nil, nil];
                
                [authalert show];
            }
        }else{
            
            NSString *returnvalue;
            NSInteger selectedview;
            Customers *customersview=[[Customers alloc]initWithNibName:@"Customers" bundle:Nil];
            for (int m=0;m<[self.navigationController.viewControllers count] ; m++)
            {
                if([[self.navigationController.viewControllers objectAtIndex:m] isKindOfClass:[Customers class]])
                {
                    returnvalue=@"yes";
                    selectedview=m;
                    break;
                }
                
            }
            if([returnvalue isEqualToString:@"yes"])
            {
                [self.navigationController popToViewController:[viewS objectAtIndex:selectedview] animated:YES];
                [self releaseViews];
            }else
            {
                
                [self.navigationController pushViewController:customersview animated:NO];
                [self releaseViews];
            }
        }
        
    }else if(selectedrow == 4){
        if ([[generalDataObject  userType] isEqualToString:@"admin"])
        {
            NSString *returnvalue;
            NSInteger selectedview;
            Employees *employeesview=[[Employees alloc]initWithNibName:@"Employees" bundle:Nil];
            for (int m=0;m<[self.navigationController.viewControllers count] ; m++)
            {
                if([[self.navigationController.viewControllers objectAtIndex:m] isKindOfClass:[Employees class]])
                {
                    returnvalue=@"yes";
                    selectedview=m;
                    break;
                }
                
            }
            if([returnvalue isEqualToString:@"yes"])
            {
                [self.navigationController popToViewController:[viewS objectAtIndex:selectedview] animated:YES];
                [self releaseViews];
            }else
            {
                
                [self.navigationController pushViewController:employeesview animated:NO];
                [self releaseViews];
            }
        }
        else
        {
            UIAlertView *authalert=[[UIAlertView alloc]initWithTitle:@"Authentication:" message:@"User not authenticated" delegate:self cancelButtonTitle:@"ok" otherButtonTitles:Nil, nil];
            
            [authalert show];
        }
        
    }else if(selectedrow == 1){
        if ([[generalDataObject  userType] isEqualToString:@"admin"])
        {
            NSString *returnvalue;
            NSInteger selectedview;
            Profile *profileview=[[Profile alloc]initWithNibName:@"Profile" bundle:Nil];
            for (int m=0;m<[self.navigationController.viewControllers count] ; m++)
            {
                if([[self.navigationController.viewControllers objectAtIndex:m] isKindOfClass:[Profile class]])
                {
                    returnvalue=@"yes";
                    selectedview=m;
                    break;
                }
                
            }
            if([returnvalue isEqualToString:@"yes"])
            {
                [self.navigationController popToViewController:[viewS objectAtIndex:selectedview] animated:YES];
                [self releaseViews];
            }else
            {
                
                [self.navigationController pushViewController:profileview animated:NO];
                [self releaseViews];
            }
        }else{
            UIAlertView *authalert=[[UIAlertView alloc]initWithTitle:@"Authentication:" message:@"User not authenticated" delegate:self cancelButtonTitle:@"ok" otherButtonTitles:Nil, nil];
            
            [authalert show];
            authalert=nil;
        }
    }else if(selectedrow == 7){
        NSString *returnvalue;
        NSInteger selectedview;
        Contacts *contactsview=[[Contacts alloc]initWithNibName:@"Contacts" bundle:Nil];
        for (int m=0;m<[self.navigationController.viewControllers count] ; m++)
        {
            if([[self.navigationController.viewControllers objectAtIndex:m] isKindOfClass:[Contacts class]])
            {
                returnvalue=@"yes";
                selectedview=m;
                break;
            }
            
        }
        if([returnvalue isEqualToString:@"yes"])
        {
            [self.navigationController popToViewController:[viewS objectAtIndex:selectedview] animated:YES];
            [self releaseViews];
        }else
        {
            
            [self.navigationController pushViewController:contactsview animated:NO];
            [self releaseViews];
        }

    }
  
    
}

-(void)releaseViews
{
    NSArray *mainArray = self.view.subviews;
    for (int i = 0; i<[mainArray count]; i++) {
        UIView *vi =[mainArray objectAtIndex:i];
        [vi removeFromSuperview];
        vi = nil;
    }
    
    NSArray *sideArray = sidemenu.subviews;
    for (int i = 0; i<[sideArray count]; i++) {
        UIView *vi =[sideArray objectAtIndex:i];
        [vi removeFromSuperview];
        vi = nil;
    }
    
    NSArray *navBarArray = navBar.subviews;
    for (int i = 0; i<[navBarArray count]; i++) {
        UIView *vi =[navBarArray objectAtIndex:i];
        [vi removeFromSuperview];
        vi = nil;
    }
    

    sidemenu=nil,mainview=nil,backgroundcolorview=nil;
    categorybutton=nil;
     downtoolBar=nil,maintoolBar=nil;
     logobackview=nil,logoimageview=nil;
    helpiconButton=nil,logouticonButton=nil,menubutton=nil;
  
    backButton3=nil,backButton2=nil,backButton=nil;
    navBar=nil;
    Reporttypelbl=nil,Searchlbl=nil;
    ReporttypeBtn=nil;
    datePicker=nil,datePicker2=nil,datePicker3=nil,datePicker4=nil;
    subview1=nil;
    btn1=nil;
    ReportTypeView=nil;
    ReportTypeTable=nil;
    [ReportTypesArray  removeAllObjects];
    ReportTypesArray=nil;
    
    fromTFDown=nil,  toTFDown=nil;
    
    sationLbl=nil,Timelbl=nil,EmpIdlbl=nil;
    logoBtn=nil;
    
    [loginID removeAllObjects],  [loginEmp removeAllObjects],  [loginEmpID removeAllObjects],  [empLoginTime removeAllObjects], [empLogoutTime removeAllObjects], [diffMin removeAllObjects],[diffHours removeAllObjects],[wages removeAllObjects],[sessionId removeAllObjects],[uniqueId removeAllObjects],[createdTimeStamp removeAllObjects],[modifiedTimeStamp removeAllObjects],[serverLocal removeAllObjects];
    
    [departmentId removeAllObjects], [departmentDis removeAllObjects],[categoryId removeAllObjects], [deptUniqueId removeAllObjects], [deptCreatedTimeStmp removeAllObjects], [deptModifiedTimeStamp removeAllObjects], [deptserverLocal removeAllObjects], [deptFoodStmp removeAllObjects], [deptTotalTax removeAllObjects],[deptCheckValue removeAllObjects];
    
      loginID=nil,  loginEmp=nil,  loginEmpID=nil,  empLoginTime=nil, empLogoutTime=nil,  diffMin=nil,diffHours=nil,wages=nil,sessionId=nil,uniqueId=nil,createdTimeStamp=nil,modifiedTimeStamp=nil,serverLocal=nil;
    
      departmentId=nil, departmentDis=nil,categoryId=nil, deptUniqueId=nil, deptCreatedTimeStmp=nil, deptModifiedTimeStamp=nil, deptserverLocal=nil, deptFoodStmp=nil, deptTotalTax=nil,  deptCheckValue=nil;
    
    [invoiceitem removeAllObjects], [invoiceDis removeAllObjects], [invoiceTotalTax removeAllObjects],[invItemName removeAllObjects], [invItemDisp removeAllObjects], [invPriceChange removeAllObjects], [invAvgCost removeAllObjects],  [invinItemQut removeAllObjects],[invID removeAllObjects], [invUniqueID removeAllObjects], [invCreatedTs removeAllObjects], [invPaymentType removeAllObjects], [invInDept removeAllObjects],[invVendor removeAllObjects], [invStoreId removeAllObjects], [invStatus removeAllObjects];
    
      invoiceitem=nil, invoiceDis=nil, invoiceTotalTax=nil,invItemName=nil, invItemDisp=nil, invPriceChange=nil, invAvgCost=nil,  invinItemQut=nil, invID=nil, invUniqueID=nil, invCreatedTs=nil, invPaymentType=nil, invInDept=nil,  invVendor=nil, invStoreId=nil, invStatus=nil;
    fromLabel=nil,  toLabel=nil,  departLabel=nil, paymentLabel=nil;
    
    departmentButton=nil,  paymentButton=nil,  goButton=nil,  saveButton=nil;
    
    
    fromTFUp=nil,  toTFUp=nil;
    
    whiteView=nil;
    blueView=nil;
    
    searchField=nil;
    
    departmentArray=nil;
    [paymentArray removeAllObjects];
      paymentArray=nil;
    departmentTV=nil,  paymentTV=nil;
    
    fromDate=nil;
    toDate=nil;
    
    itemIdLabel=nil, itemNamelabel=nil,  discountLabel=nil,  taxLabel=nil,  yourCostLabel=nil, AvgCostLabel=nil,  QuantityLabel=nil,  dateLabel=nil;
    
    fromTimePick=nil,toTimePick =nil;
    [vendorsDataArray removeAllObjects];
      vendorsDataArray=nil;
    
    displayTableView=nil, SearchlistTable=nil;
      [itemIDArray removeAllObjects],  [itemNameArray removeAllObjects],  [discountArray removeAllObjects],  [taxArray removeAllObjects],  [yourCostArray removeAllObjects],  [avgArray removeAllObjects],[quantityArray removeAllObjects], [dateArray removeAllObjects], [reportsTotalDataArray removeAllObjects],[pastDataArray removeAllObjects],[SearchDataArray   removeAllObjects];
      itemIDArray=nil,  itemNameArray=nil,  discountArray=nil,  taxArray=nil,  yourCostArray=nil,  avgArray=nil,  quantityArray=nil,  dateArray=nil, reportsTotalDataArray=nil,pastDataArray=nil, SearchDataArray  =nil;
    
    printerButton=nil;
    departmentPopUp=nil, paymentPopUp=nil;
    [departmentNamesArray removeAllObjects];
    departmentNamesArray=nil;
    
    
    //Divya Coding Values Assiging
    
    orderStatusBtn=nil, empIdBtn=nil, customerIdBtn=nil;
    
    empIdlabel=nil,  customerIdLabel=nil,  orderStatusLbl=nil;
    
   [paymentTypeArray removeAllObjects], [totalTaxArray removeAllObjects], [avgCostArray removeAllObjects],  [flashReportsArray removeAllObjects], [orderArray removeAllObjects],  [empIdArray removeAllObjects], [customerArray removeAllObjects],[ReportDepartmentsArray removeAllObjects],[ReportsItemsArray removeAllObjects] ,[printcharArray removeAllObjects],[FontsArray removeAllObjects],[languagesArray removeAllObjects],[WidthsArray removeAllObjects],[HeightsArray removeAllObjects],[boldsArray removeAllObjects],[UnderlinesArray removeAllObjects],[XpossArray removeAllObjects],[unitsArray removeAllObjects],[spacingsArray removeAllObjects],[printernamesArray removeAllObjects],[IpAddsArray removeAllObjects],[DBPrintertypesArray removeAllObjects],[PrinterIpsArray removeAllObjects] ,[ReportDepartmentsArray removeAllObjects],[ReportsItemsArray removeAllObjects];
    
      orderArray=nil,  empIdArray=nil, customerArray=nil;
    
    orderView=nil, empIdView=nil, customerView=nil;
    orderTableView=nil, empIDTableView=nil, customerTableView=nil;
    
    invoiceTableView=nil,  departmentWiseTableView=nil;
    
      paymentTypeArray=nil, totalTaxArray=nil, avgCostArray=nil,  flashReportsArray=nil;
    paymentStr=nil;
    flashReportAlertStr=nil;
     TimesArray=nil;
    
    
    PaymentAlertStr=nil;
    //stringToPrint=nil;
    CashTotalstr=nil;
    ChqueTotalstr=nil;
    cardTotalstr=nil;
   // [webView1 removeFromSuperview];
    //[webView1 loadRequest:nil];
    //webView1=nil;
   
    
    //printer
    [PrinterIpsArray removeAllObjects];
      printcharArray=nil,FontsArray=nil,languagesArray=nil,WidthsArray=nil,HeightsArray=nil,boldsArray=nil,UnderlinesArray=nil,XpossArray=nil,unitsArray=nil,spacingsArray=nil,printernamesArray=nil,IpAddsArray=nil,DBPrintertypesArray=nil,PrinterIpsArray=nil;
    
    PayPrinterName=nil,printChar=nil,font=nil,align=nil,language=nil,Pwidth=nil,Pheight=nil,Bold=nil,Underline=nil,xposition=nil,spacing=nil,Ipadd=nil,unit=nil,Dbprintertype=nil;
    
    //Fplash report View
    FlashpopupView=nil,FlashReportView=nil;
    [FlashReportWebView removeFromSuperview];
    [FlashReportWebView loadRequest:nil];
    FlashReportWebView=nil;
    PrintFlashBtn=nil,CancelFlashBtn=nil;
     ReportDepartmentsArray=nil,ReportsItemsArray=nil;
    
     invoiceCell=nil;
     reportsEmployeeCell=nil;
    
    SearchPrinterStr=nil;
     searchPrinterArray=nil;
    [self.view removeFromSuperview];
    self.view=nil;
}
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration

{
    if (toInterfaceOrientation==UIInterfaceOrientationLandscapeRight||toInterfaceOrientation==UIInterfaceOrientationLandscapeLeft) {
        isLandScope=YES;
        
    }else
    {
        isLandScope=NO;
    }
    [self updateUI];
}





- (NSUInteger)supportedInterfaceOrientations // iOS 6 autorotation fix
{
    return UIInterfaceOrientationMaskAll;
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    NSArray *viewS = [self.navigationController viewControllers];
    [self.navigationController popToViewController:[viewS objectAtIndex:1] animated:YES];
    [self releaseViews];
    // Dispose of any resources that can be recreated.
}


@end
